ant-design-vue按需加载的方法:
- 首先运行安装
npm i babel-plugin-import --dev
- 在babel.config.js中加入下面代码,如果没加,可能会出现元素有了,但样式没有:
plugins: [
[
"import",
{
libraryName: "ant-design-vue", libraryDirectory: "es", style: 'css'}
]
]
在main.js中引入:
import {
Button,
message,
Layout,
Icon,
} from 'ant-design-vue';
Vue.use(Button);
Vue.use(message);
Vue.use(Layout);
Vue.use(Icon);
如果从官网拷贝了一个组件,发现报上面的错误,那就说明没有在main.js引入该组件
Element UI按需加载的方法:
- 首先,安装 babel-plugin-component:
npm install babel-plugin-component -D
- 同样在main.js中:
import {
Select,
Button,
ButtonGroup,
Table,
}from 'element-ui';
Vue.use(Select);
Vue.use(Button);
Vue.use(ButtonGroup);
Vue.use(Table);
- 在.babelrc文件中加入下面内容:
{
"presets": [["es2015", {
"modules": false }]],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
如有写的不好的地方请指正。