码迷,mamicode.com
首页 > 其他好文 > 详细

vue 组件

时间:2018-06-03 19:23:56      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:template   one   component   return   bind   new   添加   组件   IV   

1、全局组件

<div id="box">

<aaa></aaa>

</div>

var Aaaa=Vue.extend({

template:"<h3>我是h3</h3>"

});

Vue.component(‘aaa‘,Aaa);

注:数据,组件里的数据必须是data:function(){}且必须是return一个对象

2\

Vue.component({

template:"<h3>我是h3</h3>",

data:function{

  return {

 

  };

}

})

 

3\局部组件:放到某个组件内部

<div id=‘box’>

   <aaa></aaa>

</div>

var Aaa=Vue.extend({

    template:‘<h3>这是h3</h3>‘,

 

});

var vm=new Vue({

el:"#box",

components:{

’aaa’:Aaa//局部组件注意:‘aaa‘多个字符比如my-aa时必须添加单引号‘my-aa’

}

});

动态组件

<div id=‘box’>

   <button value="aaa" v-on:click="a=‘aaa‘" ></button>

  <button value="bbb" v-on:click="a=‘bbb‘" ></button>

<component v-bind:is="a"></component>

</div>

var vm=new Vue({

el:"#box",

components:{

  ‘aaa‘:{

  template:‘<h3>这是aaa组件</h3>‘,

  },

  ‘bbb‘:{

  template:‘<h3>这是bbb组件</h3>‘,

  }

}

});

 

vue 组件

标签:template   one   component   return   bind   new   添加   组件   IV   

原文地址:https://www.cnblogs.com/Ting-log/p/9129876.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!