溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue跳轉(zhuǎn)頁簽傳參并查詢參數(shù)的方法是什么

發(fā)布時間:2023-04-15 15:35:37 來源:億速云 閱讀:103 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容主要講解“vue跳轉(zhuǎn)頁簽傳參并查詢參數(shù)的方法是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習“vue跳轉(zhuǎn)頁簽傳參并查詢參數(shù)的方法是什么”吧!

場景

需求是要求通過點擊用戶ID或者昵稱 跳轉(zhuǎn)用戶管理頁面并查詢該用戶

實現(xiàn)效果如圖

vue跳轉(zhuǎn)頁簽傳參并查詢參數(shù)的方法是什么

實現(xiàn)方法開始

在A頁面也就是筆記列表頁簽為父級 代碼如下 

<el-table v-loading="loading" :data="manageUserNoteList" @selection-change="handleSelectionChange">
 
<el-table-column label="用戶ID" align="center" prop="userId">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="查找該用戶" placement="top-start">
               <router-link  :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>

多場景vue跳轉(zhuǎn)方法 

// 字符串
<router-link to="apple"> to apple</router-link>
// 對象
<router-link :to="{path:'apple'}"> to apple</router-link>
// 命名路由
<router-link :to="{name: 'applename'}"> to apple</router-link>
//直接路由帶查詢參數(shù)query,地址欄變成 /apple?color=red
<router-link :to="{path: 'apple', query: {color: 'red' }}"> to apple</router-link>
// 命名路由帶查詢參數(shù)query,地址欄變成/apple?color=red
<router-link :to="{name: 'applename', query: {color: 'red' }}"> to apple</router-link>
//直接路由帶路由參數(shù)params,params 不生效,如果提供了 path,params 會被忽略
<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>

方法比較多 這里我使用了

動態(tài)賦值<router-link :to="...">動態(tài)傳參to里的值可以是一個字符串路徑,或者一個描述地址的對象

// 命名路由帶路由參數(shù)params,地址欄是/apple/red
<router-link :to="{name: 'applename', params: { color: 'red' }}"> to apple</router-link>

 給不知道name參數(shù)從哪來的 提個醒 這個name里的參數(shù)的 子級頁面的name 也就是你需要跳轉(zhuǎn)的那個頁面 也就是路由跳轉(zhuǎn)

vue跳轉(zhuǎn)頁簽傳參并查詢參數(shù)的方法是什么

 接收方法如下

export default {
  name: "User",
  components: { Treeselect },
  data() {
  return {}
 created() {
  //每次切換頁面重新進入次方法 此方法只用于頁面?zhèn)鲄⒏鶕?jù)userid查詢用戶
  activated () {undefined
      const userId = this.$route.params && this.$route.params.userId;
        //userid是否為空
      if (userId) {
            this.loading = true;
            //賦予userid queryParams查詢傳入查詢的字段  this.$route.params.userId接收的字段參數(shù)
            this.queryParams.userId = this.$route.params.userId;
            //我自己的搜索方法
            this.handleQuery();
        }
  },
  methods: {
}
}

獲取參數(shù)方式:this.$route.params.userId

這個userId就是{name: 'User', params: { userId: scope.row.userId }} 里params下的userId

到此,相信大家對“vue跳轉(zhuǎn)頁簽傳參并查詢參數(shù)的方法是什么”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

vue
AI