最近在写组件库,把组件库引入项目中后,把下面的错
解决方法
网上有人说是没写组件的name属性,组件必须有name属性。但是我组件都加上了name属性,也还是报这个错。那是因为没有把name属性写成驼峰形式,写成驼峰形式即解决此问题。
import '../examples/assets/yonyouicon/iconfont.css';
/* eslint-disable */
import UfButton from './UfButton';
// import Alert from './alert';
import UfCheckbox from './UfCheckbox'
import UfConfirm from './UfConfirm';
import UfDate from './UfDate';
const components = [
// Alert,
UfButton,
UfCheckbox,
UfConfirm,
UfDate,
];
const install = function(Vue,opt={}) {
if (install.installed) return;
components.map(component => {
Vue.component(component.name, component)
})
};
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue);
}
// export default install
export default{
install,
...components
};
在全局注册组件时采用遍历组件池的方法,此时,每个组件都应该具备name属性,且是驼峰形式,否则会出现如标题的错误
Uncaught TypeError: Cannot read properties of undefined (reading 'toLowerCase')