propsData 不是和屬性有關,他用在全局擴展時進行傳遞數據。
先寫一個全局擴展
var header_a = Vue.extend({
template:`{{message}} 傳值 {{ a }}`,
data:function(){
return {
message:"內容"
}
},
props:['a']
})
掛載 new header_a().$mount('header')
這時如果想傳遞值。就要用propsData
1.在全局擴展里加入props進行接收。 new header_a(propsData:{a:1}).$mount('header')
2.傳遞時用propsData進行傳遞。props:[‘a’]
3.用插值的形式寫入模板。{{ a }}