propsData传递数据

propsData 不是和属性有关,他用在全局扩展时进行传递数据。
<header id="header"></header>
<script>
var header_a=Vue.extend({
template:`<p>{{message}}{{a}}</p>`,
data:function(){
return{
message:'hello'
}
},
props:['a']
});
new header_a({propsData:{a:1}}).$mount("#header")
</script>

 如果我们要传递一个值过去,这时就用到了propsData。

使用propData传值的步骤: 

1.在全局扩展实例中:propsData:{a:1}

2.传递的时候用props接收属性:props:["a"] 

3. 写入模板:{{a}}

 

posted @ 2019-05-18 11:33  风的方向·  阅读(2895)  评论(0编辑  收藏  举报