Vue-router路由传递
一、在components中建立组件,并将其暴露
<template>
</template>
<script>
export default {
name: 'files'
}
</script>
<style>
</style>
二、主目录下main.js中使用router
import Router from 'vue-router'
Vue.use(Router);
三、在src中建立router文件夹,且在router文件夹下建立一个index.js文件
import Vue from 'vue'
import Router from 'vue-router'
import example from '../components/project/example'
import 组件名称 from '组件路径'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/renyi',
name: 'files'
component: example
}
,
{
path: '/XX',
name: 'XX'
component: 组件名称 ,
children: [
{
path: '/XX',
name: 'XX'
component: 组件名称
}
,
{
子路由2
}
]
}
]
})
四、在main.js中导入写好的路由
import roter from './router'
new Vue({
router
})
五、路由的使用
//路由的使用
//首先,需要在使用的位置使用<router-view />
//链接可跳转
<router-link to="/renyi">跳转</router-link> //此处的renyi为路由文件中的路由路径