1. 两种方式
routes: [
{
path: '/',
component: Hello
},
{
path:'/index',
component:Word
}
]
这种无论路由用不用得到这个组件,都先进行加载~性能较低
2. 箭头函数 加 import的形式,做到了懒加载,用的时候才加载,不用不加载~性能较高
3. 路由传参数
传值:query
<template>
<div>
<router-link :to="{ path: '/loading', query: {id: userId}}">button</router-link>
</div>
</template>
<script>
export default {
data () {
return {
userId: '123'
}
}
}
</script>
<style scoped>
</style>
取值:
<template>
<div>
{{this.$route.query.id}}
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>