vue項(xiàng)目中按需引入element-ui的正確實(shí)現(xiàn)方法
vue中按需引入element-ui的正確方法
1. 創(chuàng)建vue項(xiàng)目(版本@vue/cli 4.5.4):
vue create test
2. 安裝 babel-plugin-component:
npm install babel-plugin-component -D
3. 安裝element-ui:
npm install element-ui -S
4. 修改babel.config.js配置文件:
module.exports = {
? presets: [
? ? '@vue/cli-plugin-babel/preset',
? ? ["@babel/preset-env", { "modules": false }]
? ],
? "plugins": [
? ? [
? ? ? "component",
? ? ? {
? ? ? ? "libraryName": "element-ui",
? ? ? ? "styleLibraryName": "theme-chalk"
? ? ? }
? ? ]
? ]
}5. main.js中按需引入組件、全局注冊(cè)組件:
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import { Button, Input } from 'element-ui'; // 按需引入組件
// 注冊(cè)全局組件
Vue.component(Button.name, Button);
Vue.component(Input.name, Input);
/* 或?qū)憺?
?* Vue.use(Button)
?* Vue.use(Select)
?*/
?
Vue.config.productionTip = false
?
new Vue({
? router,
? store,
? render: h => h(App)
}).$mount('#app')6. 使用element-ui組件:
<template>
? <div>
? ? <!-- <input type="text" placeholder="請(qǐng)輸入任務(wù)"> -->
? ? <el-input v-model="input" placeholder="請(qǐng)輸入內(nèi)容"></el-input>
? </div>
</template>
?
<script>
? export default {
? ? name: 'MyHeader',
? ? data() {
? ? ? return {
? ? ? ? input: ''
? ? ? }
? ? }
? }
</script>
?
<style>
?
</style>elementui完整引入及按需引入項(xiàng)目開發(fā)
安裝
npm i element-ui -S
完整引入
main.js引入
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)
Vue.config.productionTip = false
new Vue({
? el: '#app',
? components: { App },
? template: '<App/>'
})按需引入
安裝
npm install babel-plugin-component -D
修改 babel.config.js文件
module.exports = {
? presets: [
? ? '@vue/cli-plugin-babel/preset'
? ],
? "plugins": [
? ? [
? ? ? "component",
? ? ? {
? ? ? ? "libraryName": "element-ui",
? ? ? ? "styleLibraryName": "theme-chalk"
? ? ? }
? ? ]
? ]
}main.js里進(jìn)行按需引入
// import ElementUI from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
// Vue.use(ElementUI)
import {
? Button,
? ButtonGroup,
} from 'element-ui';
Vue.use(Button).use(ButtonGroup)總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3?使用v-model實(shí)現(xiàn)父子組件通信的方法(常用在組件封裝規(guī)范中)
這篇文章主要介紹了Vue3?使用v-model實(shí)現(xiàn)父子組件通信(常用在組件封裝規(guī)范中)的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-06-06
vuex + keep-alive實(shí)現(xiàn)tab標(biāo)簽頁面緩存功能
這篇文章主要介紹了vuex + keep-alive實(shí)現(xiàn)tab標(biāo)簽頁面緩存功能,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10
建立和維護(hù)大型 Vue.js 項(xiàng)目的 10 個(gè)最佳實(shí)踐
這篇文章小編要與大家分享的是建立和維護(hù)大型 Vue.js 項(xiàng)目的 10 個(gè)最佳實(shí)踐,需要的小伙伴請(qǐng)和小編一起學(xué)習(xí)下面文章的具體內(nèi)容吧2021-09-09
使用vue-cli3+typescript的項(xiàng)目模板創(chuàng)建工程的教程
這篇文章主要介紹了使用vue-cli3+typescript的項(xiàng)目模板創(chuàng)建工程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-02-02

