1,全局注冊(這種方式注冊組件必須在vue實例化之前聲明)
Vue.component('tag-name',{})
2,局部注冊
var Child = { template: '<div>A custom component!</div>' } new Vue({ // ... components: { // <my-component> 將只在父模板可用 'my-component': Child } })
3,擴展實例
// 定義一個混合對象 var myMixin = { created: function () { this.hello() }, methods: { hello: function () { console.log('hello from mixin!') } } } // 定義一個使用混合對象的組件 var Component = Vue.extend({ mixins: [myMixin] }) var component = new Component() // -> "hello from mixin!"