一、Vue-router引入使用

 Vue-router就是一个vue路由类,通过new一个Vue路由实例,然后Vue.use()嵌入即可。

一般分为以下步骤:

1.引入

(1)、方法一:npm包嵌入,然后引入

import Vue from 'vue'
import VueRouter from 'vue-router'

 

(2)、CDN直接引入(练习使用)

<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>

 

2.配置路由对象+创建VueRouter实例

(1)、配置路由对象

// 路由配置对象
        const routes = [
            {
                path: '/',
                component: A
            },
            {
                path: '/A/:id',
                component: A
            },
            {
                path: '/B/:id',
                component: B
            }
        ];

 

(2)、创建VueRouter实例

// 将路由配置对象作为参数
        const router = new VueRouter({
            routes
        });

 

3.将创建的VueRouter实例传入创建的Vue实例中

const app = new Vue({
            router
        }).$mount('#app');

 

二、Vue-router路由配置

 

 

 

 

 

 

 

 

 

 

 

---------------

 

相关文章:

  • 2021-05-22
  • 2022-02-08
  • 2021-05-31
  • 2022-12-23
  • 2021-08-22
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2021-06-26
  • 2021-06-25
  • 2021-07-11
相关资源
相似解决方案