項目需要,今天嘗試引入element-ui
的Layout
組件,打開官網(wǎng),一陣搗鼓,還是沒有解決……
注:我的vue
項目是通過vue-cli
自動生成的
步驟:
1、執(zhí)行npm install babel-plugin-component -D
安裝babel-plugin-component
;
2、根據(jù)官網(wǎng)提示,修改.babelrc
,這個文件目前還不知道啥作用,我把官網(wǎng)的配置全覆蓋過來了,覆蓋了不知道會有啥影響?
{
"presets": [
["es2015", { "modules": false }]
],
"plugins": [["component", [
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]]]
}
3、引入需要的Layout
,在main.js
里面添加如下代碼
import { Layout } from 'element-ui'
Vue.use(Layout)
4、運(yùn)行npm run dev
,報錯如下:
Module build failed: Error: Couldn't find preset "es2015" relative to directory "F:\d\projects\xxx公司\pro_name"
網(wǎng)上查了一下,說是需要安裝babel-preset-es2015
,于是執(zhí)行npm install babel-preset-es2015 --save-dev
,再次 npm run dev
,又報錯了,如下:
說是3個依賴項沒有找到,順便問一下,這句npm install --save element-ui/lib/layout element-ui/lib/theme-chalk/base.css element-ui/lib/theme-chalk/layout.css
是啥意思呢?和印象中的npm install package-name --save
有些差別,執(zhí)行也報錯了,該如何解決這個問題呢?
答案:
其實上面的步驟1、2、3、4都沒有問題,但是還有一些非常重要點需要說明下,這里補(bǔ)充下:
一. 需要npm install element-ui --save
安裝該組件。
二. Layout
并不是button
、select
這種組件,但是網(wǎng)上很多答案都是input {Button、Select} from 'element-ui'
這種,所以慣性思維,直接將Button
、Select
替換成Layout
以為就ok了,直到我打開node_modules/element-ui/lib/
才發(fā)現(xiàn)這個問題(規(guī)律)——Button
、Select
都是對應(yīng)有單獨(dú)文件的,而Layout布局時,需要用到的不是Lqyout
,而是row
、col
,剛好該文件夾下就包含row.js
、col.js
,所以 應(yīng)該:
import { Row, Col } from 'element-ui'
Vue.use(Row)
Vue.use(Col)
不是應(yīng)該 npm install --save element-ui
,然后在使用的時候按需 import
,WebPack 打包的時候會自動打包用到的部分嗎。
參考:http://element-cn.eleme.io/#/... 的“按需引入”部分
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
浪潮集團(tuán)項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。