欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vue注册组件的几种方式总结

程序员文章站 2022-05-09 18:34:21
1、全局注册(这种方式注册组件必须在vue实例化之前声明) vue.component('tag-name',{}) 2、局部注册 var chi...

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注册组件的几种方式总结就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。