JavaScript

超轻量级php框架startmvc

Vue-component全局注册实例

更新时间:2020-07-25 12:54:01 作者:startmvc
组件的全局注册必须注意是在实例化对象之前完成。Vue.component("mytest",{template:'<li>{{name}

组件的全局注册必须注意是在实例化对象之前完成。


Vue.component("mytest",
{
 template:'<li>{{name}}</li>',
 props:['name']


})

new Vue({
//...
})

而局部注册则只能在父模板内使用


<div id="clear" >
<mytest v-for='li in list' v-bind:name='li'>


</mytest>

</div>


var vm=new Vue({
 el:'#clear',
 data:{
 list:[1,2,3]


 },
 components:{
 'mytest':{
 template:'<li>{{name}}</li>',
 props:['name']

 }

 }
})

以上这篇Vue-component全局注册实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

Vue component 全局注册