1 完整引入:
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
2 按需引入
(1)先安装一个按需引入需要的插件
npm install babel-plugin-component -D
(2)修改babel.config.js文件配置
module.exports = {
presets: ["@vue/app"],
plugins: [
[
"component",
{
libraryName: "element-ui",
styleLibraryName: "theme-chalk"
}
]
]
};
(3)举例引入几个组件(在main.js文件中):
import {
Pagination, Popover,
Tooltip, Table,
TableColumn, MessageBox
} from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(Pagination).use(Popover).use(Tooltip).use(Table).use(TableColumn);
// 按虚引入的话$alert 还会报错,那么有些就还是先全量引入
Vue.prototype.$alert = MessageBox.alert;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$message = Message;