// // 以数组的结构保存组件,便于遍历
const components = [RoleView, UserView, PermissionView]
// // 定义 install 方法
const install = function(Vue) {
if (install.installed) return
install.installed = true
// // 遍历并注册全局组件
components.map(component => {
Vue.component(component.name, component)
})
}
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue)
}
export default {
// // 导出的对象必须具备一个 install 方法
install,
// // 组件列表
...components
}
上面的方法测试不正常后来改用别的办法
export default {
name: 'account',
install: (Vue/* , options*/) => {
Vue.component('Accountuser', UserView)
Vue.component('Accountrole', RoleView)
Vue.component('Accountper', PermissionView)
}
}
引入之后在需要的项目里全局加载,在需要的业务页面中直接使用name标签嵌入就好
网友评论