iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >vue跳转页签传参并查询参数的保姆级教程
  • 648
分享到

vue跳转页签传参并查询参数的保姆级教程

vue跳转传参vue跳转传参查询参数vue页面传参 2023-05-15 20:05:26 648人浏览 独家记忆
摘要

目录场景实现效果如图实现方法开始方法比较多 这里我使用了场景 需求是要求通过点击用户ID或者昵称 跳转用户管理页面并查询该用户 实现效果如图 实现方法开始 在A页面也就是笔记列

场景

需求是要求通过点击用户ID或者昵称 跳转用户管理页面并查询该用户

实现效果如图

实现方法开始

在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 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>

多场景Vue跳转方法 

// 字符串
<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>
//直接路由带查询参数query,地址栏变成 /apple?color=red
<router-link :to="{path: 'apple', query: {color: 'red' }}"> to apple</router-link>
// 命名路由带查询参数query,地址栏变成/apple?color=red
<router-link :to="{name: 'applename', query: {color: 'red' }}"> to apple</router-link>
//直接路由带路由参数params,params 不生效,如果提供了 path,params 会被忽略
<router-link :to="{path: 'apple', params: { color: 'red' }}"> to apple</router-link>
// 命名路由带路由参数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>

方法比较多 这里我使用了

动态赋值<router-link :to="...">动态传参to里的值可以是一个字符串路径,或者一个描述地址的对象

// 命名路由带路由参数params,地址栏是/apple/red
<router-link :to="{name: 'applename', params: { color: 'red' }}"> to apple</router-link>

 给不知道name参数从哪来的 提个醒 这个name里的参数的 子级页面的name 也就是你需要跳转的那个页面 也就是路由跳转

 接收方法如下

export default {
  name: "User",
  components: { Treeselect },
  data() {
  return {}
 created() {
  //每次切换页面重新进入次方法 此方法只用于页面传参根据userid查询用户
  activated () {undefined
      const userId = this.$route.params && this.$route.params.userId;
        //userid是否为空
      if (userId) {
            this.loading = true;
            //赋予userid queryParams查询传入查询的字段  this.$route.params.userId接收的字段参数
            this.queryParams.userId = this.$route.params.userId;
            //我自己的搜索方法
            this.handleQuery();
        }
  },
  methods: {
}
}

获取参数方式:this.$route.params.userId

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

到此这篇关于vue如何跳转页签传参并查询参数(保姆级)的文章就介绍到这了,更多相关vue跳转传参内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: vue跳转页签传参并查询参数的保姆级教程

本文链接: https://www.lsjlt.com/news/209452.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作