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!"以上這篇vue注冊組件的幾種方式總結就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答