admin 管理员组

文章数量: 887019

还能怎么办,手动配呗,麻烦!

第一步:安装router

cnpm install vue-router -S

第二步:在src下新建router文件夹,并在router下创建index.js

第三步:编辑index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import TestNexttick from '../components/Test_nexttick.vue'//引入组件

Vue.use(VueRouter)

const routes = [//添加路由对象
  {
    path: '/TestNexttick',
    name: 'TestNexttick',
    component: TestNexttick
  },
]

const router = new VueRouter({
  mode:'history',//采用哪种路由模式,默认是history,可改为hash
  routes
})

export default router

第四步:修改main.js

import Vue from 'vue'
import App from './App.vue'
import router from './router'//新增
import store from './store'

Vue.config.productionTip = false

new Vue({
  router,//新增
  store,
  render: h => h(App)
}).$mount('#app')

第五步:在根目录App.vue中可以使用了

<template>
  <div id="app">
    <div id="nav">
      <router-link to="/TestNexttick">TestNexttick测试</router-link> |
    </div>
    <router-view/>
  </div>
</template>

本文标签: 发现 Vue router