# 全局安裝 vue-cli
$ npm install --global vue-cli
# 創建一個基於 webpack 模板的新項目
$ vue init webpack my-project
# 安裝依賴,走你
$
cd my-project
$ npm install
$ npm run dev
在config里index.js改配置自動打開瀏覽器
安裝路由
下載
npm i vue-router -S
創建router.js文件配置
1 //引包 2 import VueRouter from 'vue-router' 3 //導入對應的路由組件 4 import Home from './components/home.vue' 5 //創建路由對象 6 var router = new VueRouter({ 7 routes:[ 8 //配置路由規則 9 {path:'/',redirect:'/home'}, 10 {path:'/home',component:Home} 11 ] 12 }) 13 14 //把路由對象暴露出去 15 export default router
main.js文件配置
1 import Vue from 'vue' 2 import App from './App' 3 4 /*1.1導入路由的包*/ 5 import VueRouter from 'vue-router' 6 /*1.2 安裝路由*/ 7 Vue.use(VueRouter) 8 9 /*1.3 導入自己的router。js路由模塊*/ 10 import router from './router.js' 11 12 13 /* eslint-disable no-new */ 14 new Vue({ 15 el: '#app', 16 components: { App }, 17 template: '<App/>', 18 /*1.4 掛載路由對象到VM實例上*/ 19 router 20 })
在App.vue文件中通過router-view標簽引用顯示內容
//內容content <transition> <router-view></router-view> </transition>
通過router-link標簽to跳轉
<router-link class="mui-tab-item" to="/home">
<router-link class="mui-tab-item" to="/home"> <span class="mui-icon mui-icon-home"></span> <span class="mui-tab-label">首頁</span> </router-link>