解讀Vue-Router?使用?prams?路由傳參失效
報(bào)錯(cuò)信息: [Vue Router warn]: Discarded invalid param(s) “name”, “price”, “id” when navigating.

list.json
{
"data": [
{
"name": "面",
"price":300,
"id": 1
},
{
"name": "水",
"price":400,
"id": 2
},
{
"name": "菜",
"price":500,
"id": 3
}
]
}login.vue
<template>
<h1>
我是列表頁(yè)面
</h1>
<table cellpadding="0" class="table" border="1">
<thead>
<tr>
<th>商品</th>
<th>價(jià)格</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr :key="item.id" v-for="item in data">
<th>{{ item.name }}</th>
<th>{{ item.price }}</th>
<th>
<button @click="toDetail(item)">詳情</button>
</th>
</tr>
</tbody>
</table>
</template>
<script setup lang="ts">
import { data } from './list.json'
import { useRouter } from 'vue-router';
const router = useRouter()
type Item = {
name: string;
price: number;
id: number;
}
const toDetail = (item: Item) => {
router.push({
// name 對(duì)應(yīng) router 的 name
name: 'Reg',
// 不會(huì)展示在URL上,存在于內(nèi)存里
params: item
})
}
</script>
<style scoped>
.table {
width: 400px;
}
</style>reg.vue
<template>
<h1>
我是列表頁(yè)面
</h1>
<button @click="router.back()">返回</button>
<div style="font-size: 20px;">
品牌:{{ route.params.name }}
</div>
<div style="font-size: 20px;">
價(jià)格:{{ route.params.price }}
</div>
<div style="font-size: 20px;">
id: {{ route.params.id }}
</div>
</template>
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { useRouter } from 'vue-router';
const router = useRouter();
const route = useRoute();
</script>
<style scoped>
.reg {
background-color: green;
height: 400px;
width: 400px;
font-size: 20px;
color: white;
}
</style>App.vue
<template>
<h1>hello world</h1>
<hr>
<router-view></router-view>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();
</script>
<style scoped></style>
此時(shí)得到的 params 數(shù)據(jù)為空
然后查看更新日志:點(diǎn)擊查看更新日志

所以,這種使用 prams 路由傳參的方法失效。
到此這篇關(guān)于Vue-Router 使用 prams 路由傳參失效的文章就介紹到這了,更多相關(guān)Vue Router 使用 prams 路由傳參內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue中this.$router.go(-1)失效(路由改變了,界面未刷新)
- vue3使用vue-router嵌套多級(jí)路由的方法
- vue中路由router配置步驟詳解
- 在vue中路由使用this.$router.go(-1)返回兩次問(wèn)題
- Vue?router?路由安裝及使用過(guò)程
- vue使用動(dòng)態(tài)添加路由(router.addRoutes)加載權(quán)限側(cè)邊欄的方式
- vue3中使用router路由實(shí)現(xiàn)跳轉(zhuǎn)傳參的方法
- vue3使用vue-router及路由權(quán)限攔截方式
- Vue3使用vue-router如何實(shí)現(xiàn)路由跳轉(zhuǎn)與參數(shù)獲取
- Vue中vue-router路由使用示例詳解
相關(guān)文章
vuex中五大屬性和使用說(shuō)明(包括輔助函數(shù))
這篇文章主要介紹了vuex中五大屬性和使用說(shuō)明(包括輔助函數(shù)),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05
Vue 動(dòng)態(tài)添加路由及生成菜單的方法示例
這篇文章主要介紹了Vue 動(dòng)態(tài)添加路由及生成菜單的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
vue 項(xiàng)目集成 electron 和 electron 打包及環(huán)境配
文章介紹了如何使用Vue和Electron開(kāi)發(fā)桌面端應(yīng)用,包括安裝Electron、配置package.json、創(chuàng)建main.js文件、運(yùn)行和打包應(yīng)用等步驟,并分享了一些常見(jiàn)的打包錯(cuò)誤及其解決方法,感興趣的朋友一起看看吧2025-01-01
vue?watch中如何獲取this.$refs.xxx節(jié)點(diǎn)
這篇文章主要介紹了vue?watch中獲取this.$refs.xxx節(jié)點(diǎn)的方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
Vue實(shí)現(xiàn)省市區(qū)級(jí)聯(lián)下拉選擇框
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)省市區(qū)級(jí)聯(lián)下拉選擇框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
Vue.js每天必學(xué)之指令系統(tǒng)與自定義指令
Vue.js每天必學(xué)之指令系統(tǒng)與自定義指令,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09

