學(xué)習(xí)地址
一、在一個(gè)文件夾中按住shift的同時(shí),點(diǎn)擊鼠標(biāo)右鍵,打開命令窗口
首先創(chuàng)建三個(gè)項(xiàng)目,main、test、common,其中common是公共組件,main和test引用了common包。
vue create main
vue create test
vue create common
二、common包入口
創(chuàng)建完成后刪除common包一些無用的東西,修改package.json,增加一行 "main": "index.js", 這表明index.js就是common包的入口文件,然后創(chuàng)建index.js文件。

index.js文件
index.js中需包含上面說的第三方組件初始化和公共組件的導(dǎo)出,本示例完整內(nèi)容如下
import WeVue from 'we-vue'
import 'we-vue/lib/style.css'
import Vue from 'vue'
import playerPicker from './src/components/playerPicker'? //導(dǎo)出的組件
Vue.use(WeVue)
export {
? playerPicker
}
三、common包的使用
分別進(jìn)入main和test,在控制臺(tái)輸入命令:
npm install ../common/
其中…/common/是common的相對(duì)路徑,這里也可以輸入絕對(duì)路徑。
這樣就將common這個(gè)工程以node_module的方式引入到main和test項(xiàng)目中了??梢哉J褂胏ommon在index.js中導(dǎo)出的組件了。
命令執(zhí)行完后,package.json里會(huì)多一條記錄

四、common包中組件的使用
引入公共組件 公共組件創(chuàng)建好了,需要引入,引入代碼和引入其他組件的方式一樣,代碼如下:
