cnpm install vue-cli -g
vue init webpack projectName
npm run dev
修改端口運行
PORT=8089 node ./build/dev-server.js
cnpm install vue-router --save-dev
import VRouter from 'vue-router'
//使用
Vue.use(VRouter)
import Home from '@/page/home'
import News from '@/page/news'
let router = new VRouter({
routes:[
{path:'/home',component:Home},
{path:'/news',component:News}
]
})
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
在跟組件中 App.vue中 加入<router-view></router-view>,肯定顯示區域
localhost:8080/#/home
localhost:8080/#/news
import Vue from 'vue'
//路由相關
//載入vue-router
import VRouter from 'vue-router'
//使用
Vue.use(VRouter)
//導入模塊
import Home from '@/page/home'
import News from '@/page/news'
export default new VRouter({
routes:[
{path:'/home',component:Home},
{path:'/news',component:News}
]
})
main.js
import router from '@/route/index'