vue-router 的安装使用

1.安装;

在指定的文件中,命令行输入:npm install vue --save -router

2.引用

2.1新建一个js文件,

2.2 然后在文件中输入;

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

3配置文件

在router.js中写

export default new VueRouter({
    routes:[
        {path:'/',component:Home,name:'Home'},
       
    ],
    mode:'history'

})

vue-router 的安装使用_第1张图片

4视图加载位置: 如在app.vue中添加


vue-router 的安装使用_第2张图片

5.获取当前 路由的路径;

this.$route.path
 
  

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(vue.js)