Vue注册组件的几种方式

全局注册

该方式注册组件必须在vue实例化之前声明

Vue.component('tag-name', {})

局部注册

var Child = {
  template: '<div>A custom component!</div>'
}
new Vue({
  // ...
  components: {
    // <my-component> 将只在父模板可用
    'my-component': Child
  }
})

扩展实例

// 定义一个混合对象
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项目中使用qrcode生成二维码
下一篇 Vue.js async与await解析
目录
文章列表
1 Linux下MySQL为用户分配指定数据库
Linux下MySQL为用户分配指定数据库
2
CentOS下安装配置PHP 7
CentOS下安装配置PHP 7
3
Vuex核心概念解析State Getters Mutations Actions
Vuex核心概念解析State Getters Mutations Actions
4
Spring Cloud消息总线RabbitMQ方式
Spring Cloud消息总线RabbitMQ方式
5
Gitlab大版本升级思路
Gitlab大版本升级思路
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。