预留广告位
预留广告位
预留广告位
当前位置:首页  »  科技  »  科技百科  »  文章  »  vue route

vue route

来源:网络 转载:好巧合 时间:2022-01-22 21:31
导读vue route,vue一般来说也就是Vue路由,即可以根据不同地址,创造不同页面。而route即一个路由,路由是url到函数的映射,它能够将url路径与一个函数进行映射,当然,route也能够相当于当前正在跳转的对象,可从里面获取name、path、params、query等。

vue route是怎样的呢?下面就让我们一起来了解一下吧:

vue一般来说也就是Vue路由,即可以根据不同地址,创造不同页面。而route即一个路由,路由是url到函数的映射,它能够将url路径与一个函数进行映射,当然,route也能够相当于当前正在跳转的对象,可从里面获取name、path、params、query等。

拓展:

在vue中使用vue-route的方式:

1、首先需要下载vue-router

即npm install vue-router --save

2、进行编码

1.需要先在项目中新建文件夹router/index.js。具体指令为:

/*

* 路由对象模块

* */

import Vue from 'vue'

import VueRouter from 'vue-router'

/*引入pages*/

const MSite = ()=>import('../pages/MSite/MSite');

const Profile = ()=>import('../pages/Profile/profile');

const Patient = ()=>import('../pages/Patient/Patient');

//申明使用插件

Vue.use(VueRouter)

export default new VueRouter({

  routes:[

    {

      path:'/msite',

      component: MSite,

      meta: {

        showFooter: true

      }

    },

    {

      path:'/profile',

      component:Profile,

      meta: {

        showFooter: true

      }

    },

    {

      path:'/patient',

      component:Patient,

      meta: {

        showFooter: false

      }

    },

    {

      path: '/',

      redirect: '/msite' //系统默认页

    }

  ]

})

2.接着就可以在main.js中全局使用router了,具体指令为:

// The Vue build version to load with the `import` command

// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from 'vue'

import App from './App'

import router from './router' //引入路由

/* eslint-disable no-new */

new Vue({

  el: '#app',

  components: { App },

  template: '<App/>',

  router  //引入路由

})

以上就是小编的分享了,希望能够帮助到大家。

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。

预留广告位
标签:vue  route  
Top