<router-link
:to="{ name: 'MyRouter', query: { username: '张三' } }"
>点击获取用户名</router-link
>
在路由名为MyRouter的组件中,进行打印测试:
console.log(this.$route.query.username)
建议写computed中,然后继续获取:
computed: {
cpntTitle: function() {
return this.$route.query.username
}
html中:
<span>{{ cpntTitle }}</span>
methods中:
methods: {
printCpntTitle() {
console.log(this.cpntTitle)
}
}