當前位置:科普知識站>IT科技>

vue|route

IT科技 閱讀(2.47W)

vue一般來說也就是Vue路由,即可以根據不同地址,創造不同頁面。而route即一個路由,路由是url到函式的對映,它能夠將url路徑與一個函式進行對映,當然,route也能夠相當於當前正在跳轉的物件,可從裡面獲取name、path、params、query等。

vue route

拓展:

在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' //系統預設頁

    }

  ]

})

vue route 第2張

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  //引入路由

})