美文网首页
vue-router

vue-router

作者: 不染事非 | 来源:发表于2019-03-30 09:32 被阅读0次

1.安装 路由插件

npm install vue-router --save-dev  

2.配置
两种配置方法:在main.js中 || 在src/router文件夹下的index.js中
这里只说在src/router/index.js中的
1.引入

import Vue from 'vue'
 
import Router from 'vue-router'

注意这个Router是自定义的名字,这里叫这个名字后,下边都要用到的
2.使用/注册:

Vue.use(Router)

3.配置
方法一

const options = [{
    path: '/',
    components: () =>
        import ('@/App')
}, {
    path: '/Swipe',
    components: () =>
        import ('@/views/Swipe')
}]
const router = new Router({
    routes: options
});
export default router

方法二

export default new Router({
  routes: [
   {
        path : ‘/’,  //到时候地址栏会显示的路径
        name : ‘Home’,
        component :  Home   // Home是组件的名字,这个路由对应跳转到的组件。。注意component没有加“s”.
    },
    {
        path : ‘/content’,
        name : ‘Content’,
        component :  Content
    }
],
    mode: "history"
})

4. 引入路由对应的组件地址:

import Home from '@/components/Home'
 
import Home from '@/components/Content’
  1. 在main.js中调用index.js的配置:
import router from './router'

相关文章

网友评论

      本文标题:vue-router

      本文链接:https://www.haomeiwen.com/subject/svxjbqtx.html