1. cd到工作目錄
2. npm init -y
3. 先查看有沒有安裝全局的vue-cli,:vue-V,沒有的話安裝一下:npm install vue-cli
4. 創建項目: vue init webpack Luffy (項目名)
如果出問題: Mac安裝Vue-cli時 提示bash: vue: command not found問題
http://www.cnblogs.com/wz2018/p/9849000.html
? Project name luffy
? Project description A Vue.js project
? Author
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created?(recommended) (Use arrow keys)
❯ Yes, use NPM
5. 項目啟動 npm run dev
目錄結構:
build: 出口文件,webpack配置文件
src: 工作目錄 main 主入口文件
index.js: 注冊組件
component 創建組件,
app.vue 中注冊
重啟項目 需要cd 進入自己建立的項目下 然后 npm run dev
使用element-ui
1. 在 main.js 中寫入以下內容:
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
加載: Vue.use(ElementUI);
2. MyHeader中添加組件
復制到組件中, 根據條件添加 data數據
添加路由:
1. component中建立組件,
2. 在index.js中注冊組件 先導入組件, 有多少個注冊多少個組件, path:'/', name:'xxx', component:組件名
3. template中 標簽添加 :router="true"
4. app.vue中 添加 <router-view></router-view>
打包
npm run build
VUEX 組件通信
1. cd 到項目目錄,安裝 npm i vuex
2. 不解耦: 導入/use/實例化/注冊
解耦: 新建store.js,導入vue,vuex/use/export, main.js導入,注冊