vue中页面跳转传值_vue的页面跳转方式和传值、取值
生活随笔
收集整理的這篇文章主要介紹了
vue中页面跳转传值_vue的页面跳转方式和传值、取值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
寫業務中,從一個頁面跳轉到另一個頁面,經常需要傳值和取值,如何實現?
1、通過router-link進行跳轉,傳遞方式:
使用query傳遞參數,路由必須使用path引入,
使用params傳遞參數,路由必須使用name引入
跳轉
跳轉地址 ====> /home?key=hello&value=world
取值 ====> this.$route.query.key
跳轉
跳轉地址 ====> /home
取值 ====> this.$route.params.key
2、$router方式跳轉
通過query
this.$router.push({
path: '/detail',
query: {
name: 'admin',
code: 10021
}
});
跳轉地址 ====> /detail?name=admin&code=10021
取值 ====> this.$route.query.name
通過params
this.$router.push({
name: 'detail',
params: {
code: 10021
}
});
跳轉地址 ====> /detail(注意:地址不會有參數,所以頁面刷新傳遞的數據就沒了)
取值 ====> this.$route.params.code
總結
以上是生活随笔為你收集整理的vue中页面跳转传值_vue的页面跳转方式和传值、取值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 已经无法合并还报请合并git_GIT 分
- 下一篇: db2数据库连接数 linux_linu