iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >Vue+ElementUi实现点击表格中链接进行页面跳转与路由详解
  • 577
分享到

Vue+ElementUi实现点击表格中链接进行页面跳转与路由详解

摘要

目录1、页面跳转,先看效果2、路由切换加传参数,先看效果总结1、页面跳转,先看效果 点击表格中的asin会跳转到亚马逊购物界面 怎么做的呢,直接上代码 <el-table-

1、页面跳转,先看效果

点击表格中的asin会跳转到亚马逊购物界面

怎么做的呢,直接上代码

<el-table-column
        prop="asin"
        label="asin"
        width="150"
        fixed>
        <template slot-scope="scope">
          <el-link :href="scope.row.url" rel="external nofollow"  type="primary" target="_blank">{{scope.row.asin}}</el-link>
        </template>
      </el-table-column>

asin那一列通过<template>标签把scope传进去,scope是包含这一行的信息的,在标签里面使用<el-link>标签配合数据里面的url实现页面跳转,获取某个属性可以通过scope.row.属性名 获取

2、路由切换加传参数,先看效果

 点击标题

可以看到路由切换到产品分析了,并且asin数据也传递过去了

实现直接看代码

<el-table-column
        prop="title"
        label="标题"
        width="150"
        :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <router-link :to= "{name: 'productsAnalysis',params: {asin: scope.row.asin }}">
            <span>
              {{scope.row.title}}
            </span>
          </router-link>
        </template>
      </el-table-column>

可以看到路由切换与页面跳转类似,都是通过<template>标签实现的,区别就是<router-link>里面直接

{{scope.row.title}}不好使,需要借助<span>标签实现内容展示

路由切换使用路由名字

productsAnalysis,点击标题时路由器会找到productsAnalysis路由,并且把参数params传过去,看一下我的路由怎么实现的吧

{
    path: '/console',
    component: Layout,
    redirect: '/console/productsAnalysis',
    name: 'console',
    meta: { title: '销售', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'productsAnalysis',
        name: 'productsAnalysis',
        component: () => import('@/views/products/productsAnalysis'),
        meta: { title: '产品分析', icon: 'table' }
      },
      {
        path: 'productPerspective',
        name: 'productPerspective',
        component: () => import('@/views/products/productPerspective'),
        meta: { title: '产品透视', icon: 'table' }
      }
    ]
  },

可以看到路由名为productsAnalysis的会跳转到

@/views/products/productsAnalysis组件

 看一下productsAnalysis组件怎么拿到参数的

<template>
<dev>
  <h1>ProductsAnalysis</h1>
  <h1>{{asin}}</h1>
</dev>
</template>
 
<script>
import router from '@/router'
export default {
  data(){
    return{
      asin: null
    }
  },
  created() {
    this.asin = this.$route.params.asin
  }
}
</script>
 
<style scoped>
 
</style>

直接

this.$route.params.asin就能拿到路由传过来的参数

总结

到此这篇关于Vue+ElementUi实现点击表格中链接进行页面跳转与路由的文章就介绍到这了,更多相关Vue ElementUi点击链接页面跳转和路由内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Vue+ElementUi实现点击表格中链接进行页面跳转与路由详解

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

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

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

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

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

  • 微信公众号

  • 商务合作