今天嘗試以props傳送Array類資料時,
發現Array傳送到component時變成了string
查了很久都沒查出由來,
請各位大大幫忙一下。
vue透過script運行 <script src="https://unpkg.com/vue@latest/dist/vue.min.js"></script>
index.html
<section id="blogs">
    <blog :title="blogs[0].title" :date="blogs[0].date" :paragraphs="blogs[0].paragraph" :blog="[blogs[0].paragraph]"></blog>
</section>
main.js (主頁的js檔 DATA的部份)
用array的原因是不止一個
    data: {
        blogs:[
            {
                title:"測試用文章",
                date:"5 Aug",
                paragraph:[
                    "hihi is for testing",
                    "2nd paragraph"
                ]
            },
        ]
    },
blog.js (component的部份)
Vue.component('blog', {
    template:
        `
        <div class="container">
            <h2>{{title}}</h2>
            <div>{{date}}</div>
            <p>{{paragraphs}}</p>
            <p>{{typeof(paragraphs)}}
            <p v-for ="(paragraph, i) in paragraphs" v-html="paragraph"></p>
        </div>
                `,
    props: {
        title: {
            type: String,
            required: true,
        },
        date: {
            type: String,
            required: true,
        },
        paragraphs: {
            type: Array,
            required: true,
        },
    },
})
let blog = new Vue({
    el: '#blogs',
})
下圖是出來的結果...