vue.js(16)--vue的组件

注册一个全局组件

<div id="app">
    <test></test>
</div>
 
<script>
// 注册全局组件
Vue.component('test', {
  template: '<h1>自定义组件!</h1>'
})
// 创建根实例
new Vue({
  el: '#app'
})
</script>

创建一个局部组件(只能在父模板中使用)

<div id="app">
    <test></test>
</div>
 
<script>
var Child = {
  template: '<h1>自定义组件!</h1>'
}
new Vue({
  el: '#app',
  components: {
    'test': Child
  }
})
</script>

猜你喜欢

转载自www.cnblogs.com/qiqisusu/p/11370627.html
今日推荐