vue路由跳轉傳遞參數:
1、使用params,但是這種方式在頁面刷新的時候會出現很多問題,需要在路由中配置
2、使用query,頁面刷新不會存在問題,也不需要在路由中配置。
{
path:'/detail',
component: detail,
}
使用方法:
傳遞參數(JS中):
this.$router.push({
path: '/detail', query:{shopid: item.id}
});
傳遞參數(頁面中):
<router-link :to="{ path:'/detail', query: {shopid: item.id} }"><button>顯示<button></router-link>
<router-link :to="`/detail?id=${item.id}`"><button>顯示</button></router-link>
獲取參數:
this.$route.query.shopid
url的表現形式(url中帶有參數):
http://localhost:8080/#/detail?shopid=1