vue中的插件封装

// 封装一个插件,目的全局注册components下所有的组件。

(一)

//导入组件(想要注册的组件)
import MyCom from '@/components/my-com'


export default {

//使用固定的函数install()来完成注册里面的参数‘Vue’必须携带
install (Vue) {
// Vue 对象 main.js 使用 Vue.use(插件) 调用install函数,传入当前的Vue对象
Vue.component(MyCom.name, MyCom)//(说明一下MyCom.name是导入组件下的名字,)
}
}

(二)

//在main.js 中使用插件

import myPlugin from '@/components'
Vue.use(myPlugin)

猜你喜欢

转载自www.cnblogs.com/lxsunny/p/12750306.html