美文网首页
开发插件的步骤

开发插件的步骤

作者: 年轻人多学点 | 来源:发表于2020-03-20 11:26 被阅读0次
// // 以数组的结构保存组件,便于遍历
 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标签嵌入就好

相关文章

网友评论

      本文标题:开发插件的步骤

      本文链接:https://www.haomeiwen.com/subject/zpzdyhtx.html