vue跳轉(zhuǎn)頁(yè)簽傳參并查詢(xún)參數(shù)的保姆級(jí)教程
場(chǎng)景
需求是要求通過(guò)點(diǎn)擊用戶(hù)ID或者昵稱(chēng) 跳轉(zhuǎn)用戶(hù)管理頁(yè)面并查詢(xún)?cè)撚脩?hù)
實(shí)現(xiàn)效果如圖


實(shí)現(xiàn)方法開(kāi)始
在A頁(yè)面也就是筆記列表頁(yè)簽為父級(jí) 代碼如下
<el-table v-loading="loading" :data="manageUserNoteList" @selection-change="handleSelectionChange">
<el-table-column label="用戶(hù)ID" align="center" prop="userId">
<template slot-scope="scope">
<el-tooltip class="item" effect="dark" content="查找該用戶(hù)" placement="top-start">
<router-link style="color: #00aaff;" :to="{name: 'User', params: { userId: scope.row.userId }}">{{scope.row.userId}}</router-link>
</el-tooltip>
<!-- <el-link type="primary" :to="{name: 'User', params: { userId: scope.row.userId }}" >{{scope.row.userId}}</el-link> -->
</template>
</el-table-column>
</el-table>多場(chǎng)景vue跳轉(zhuǎn)方法
// 字符串
<router-link to="apple"> to apple</router-link>
// 對(duì)象
<router-link :to="{path:'apple'}"> to apple</router-link>
// 命名路由
<router-link :to="{name: 'applename'}"> to apple</router-link>
//直接路由帶查詢(xún)參數(shù)query,地址欄變成 /apple?color=red
<router-link :to="{path: 'apple', query: {color: 'red' }}"> to apple</router-link>
// 命名路由帶查詢(xún)參數(shù)query,地址欄變成/apple?color=red
<router-link :to="{name: 'applename', query: {color: 'red' }}"> to apple</router-link>
//直接路由帶路由參數(shù)params,params 不生效,如果提供了 path,params 會(huì)被忽略
<router-link :to="{path: 'apple', params: { color: 'red' }}"> to apple</router-link>
// 命名路由帶路由參數(shù)params,地址欄是/apple/red
<router-link :to="{name: 'applename', params: { color: 'red' }}"> to apple</router-link>
// 其他方式
<router-link :to="'/system/user/' + scope.row.userId" class="link-type">
<span>{{ scope.row.userId }}</span>
</router-link>方法比較多 這里我使用了
動(dòng)態(tài)賦值<router-link :to="...">動(dòng)態(tài)傳參,to里的值可以是一個(gè)字符串路徑,或者一個(gè)描述地址的對(duì)象
// 命名路由帶路由參數(shù)params,地址欄是/apple/red
<router-link :to="{name: 'applename', params: { color: 'red' }}"> to apple</router-link>給不知道name參數(shù)從哪來(lái)的 提個(gè)醒 這個(gè)name里的參數(shù)的 子級(jí)頁(yè)面的name 也就是你需要跳轉(zhuǎn)的那個(gè)頁(yè)面 也就是路由跳轉(zhuǎn)

接收方法如下
export default {
name: "User",
components: { Treeselect },
data() {
return {}
created() {
//每次切換頁(yè)面重新進(jìn)入次方法 此方法只用于頁(yè)面?zhèn)鲄⒏鶕?jù)userid查詢(xún)用戶(hù)
activated () {undefined
const userId = this.$route.params && this.$route.params.userId;
//userid是否為空
if (userId) {
this.loading = true;
//賦予userid queryParams查詢(xún)傳入查詢(xún)的字段 this.$route.params.userId接收的字段參數(shù)
this.queryParams.userId = this.$route.params.userId;
//我自己的搜索方法
this.handleQuery();
}
},
methods: {
}
}獲取參數(shù)方式:this.$route.params.userId
這個(gè)userId就是{name: 'User', params: { userId: scope.row.userId }} 里params下的userId
到此這篇關(guān)于vue如何跳轉(zhuǎn)頁(yè)簽傳參并查詢(xún)參數(shù)(保姆級(jí))的文章就介紹到這了,更多相關(guān)vue跳轉(zhuǎn)傳參內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue3中使用router路由實(shí)現(xiàn)跳轉(zhuǎn)傳參的方法
- Vue路由跳轉(zhuǎn)傳參或者打開(kāi)新頁(yè)面跳轉(zhuǎn)問(wèn)題
- vue3.0?router路由跳轉(zhuǎn)傳參問(wèn)題(router.push)
- vue項(xiàng)目實(shí)例中用query傳參如何實(shí)現(xiàn)跳轉(zhuǎn)效果
- vue3 攜帶參數(shù)跳轉(zhuǎn)|router傳參方式
- vue跳轉(zhuǎn)方式(打開(kāi)新頁(yè)面)及傳參操作示例
- vue路由跳轉(zhuǎn)傳參數(shù)的方法
- vue路由對(duì)不同界面進(jìn)行傳參及跳轉(zhuǎn)的總結(jié)
相關(guān)文章
Vue升級(jí)帶來(lái)的elementui沖突警告:Invalid prop: custom va
在頁(yè)面渲染的時(shí)候,控制臺(tái)彈出大量警告,嚴(yán)重影響控制臺(tái)的信息獲取功能,但是頁(yè)面基本能正常顯示,這是因?yàn)閂ue升級(jí)帶來(lái)的elementui沖突警告: Invalid prop: custom validator check failed for prop “type“.的解決方案,本文給大家介紹了詳細(xì)的解決方案2025-04-04
vue使用html2canvas實(shí)現(xiàn)將DOM節(jié)點(diǎn)生成對(duì)應(yīng)的PDF
這篇文章主要為大家詳細(xì)介紹了vue如何使用html2canvas實(shí)現(xiàn)將DOM節(jié)點(diǎn)生成對(duì)應(yīng)的PDF,文中的示例代碼簡(jiǎn)潔易懂,感興趣的小伙伴可以學(xué)習(xí)一下2023-08-08
Vue3新特性Suspense和Teleport應(yīng)用場(chǎng)景分析
本文介紹了Vue2和Vue3中的Suspense用于處理異步請(qǐng)求的加載提示,以及如何在組件間實(shí)現(xiàn)動(dòng)態(tài)加載,同時(shí),Teleport技術(shù)展示了如何在DOM中靈活地控制組件的渲染位置,解決布局問(wèn)題,感興趣的朋友跟隨小編一起看看吧2024-07-07
Vue 頁(yè)面監(jiān)聽(tīng)用戶(hù)預(yù)覽時(shí)間功能的實(shí)現(xiàn)代碼
這篇文章主要介紹了Vue 頁(yè)面如何監(jiān)聽(tīng)用戶(hù)預(yù)覽時(shí)間,首先需要借助vue頁(yè)面的生命周期函數(shù)mounted和destroyed,分別加入開(kāi)始計(jì)時(shí)和清除計(jì)時(shí)的邏輯,通過(guò)相關(guān)操作實(shí)現(xiàn)此功能,需要的朋友可以參考下2021-07-07
Vue3實(shí)現(xiàn)雙向綁定的基本原理和代碼示例解析
Vue3中的響應(yīng)式系統(tǒng)由Proxy實(shí)現(xiàn),它取代了Vue2中的Object.defineProperty,提供了更強(qiáng)大的功能和更好的性能,下面給大家介紹Vue3實(shí)現(xiàn)雙向綁定的基本原理和代碼示例解析,感興趣的朋友一起看看吧2024-12-12

