欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue項(xiàng)目中按需引入element-ui的正確實(shí)現(xiàn)方法

 更新時(shí)間:2023年01月10日 14:16:42   作者:每一天,每一步  
這篇文章主要介紹了vue項(xiàng)目中按需引入element-ui的正確實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

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)目開(kāi)發(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)文章

最新評(píng)論