在搭建前端组件库项目时,写好自己的组件库,然后发布到npm ,在另一个项目中引用发的的组件时,出现 validateComponentName Uncaught TypeError: Cannot read property 'toLowerCase' of undefined 错误,
组件是以插件的方式全局安装的,因此需要组件项目中有个index文件,提供了install 方法,如下:
const install = function (Vue) {
if (install.installed) return
components.map(component => Vue.component(component.name, component))
}
这个组件注册时会验证每个组件的名字,我注册的某个组件在其xx.vue 中 声明 name: xxx, 具体例子:
export default {
name: 'dxy-modal', // name属性没写导致项目使用组件出错
data () {
return {
}
}
}