<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)
}
}