Vue3给table表格字段,添加超级链接,点击后跳转

问题:给名称字段添加链接,实现点击跳转
在这里插入图片描述
1.给name列添加扩展内容

<template>
  <el-table :data="tableData" style="width: 100%">
       <!-- 获取id -->
    <el-table-column prop="id" label="#ID" width="60"> </el-table-column>
    
      <!-- 获取名字 -->
    <el-table-column prop="name" label="名称" width="100">
    <!-- scope代表的是当前列的填充数据 -->
      <!-- 丰富table标签,用 <template #default="scope">标签进行扩展 -->
      <template #default="scope">
         
         <!-- name:跳转的地址  query根据id进行查询-->
        <router-link :to="{ name: 'about', query: { id: scope.row.id } }">
         <!-- 当前列取值-->
          {{ scope.row.name }}
          </router-link>
     
      </template>
    </el-table-column>
 
  <!-- 获取图片 -->
    <el-table-column prop="img" label="图片">
      <template #default="scope">
        <el-image
          style="width: 100px; height: 100px"
          :src="scope.row.img"
          fit="contain"
        />
      </template>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { ref, onMounted } from "vue";
import http from "@/http/index";

//定义变量是需要用ref包裹一下
const tableData = ref([]);

//onMounted当页面加载时,显示数据
onMounted(() => {
  http
    .get("/api/products2")
    .then((res: any) => {
      tableData.value = res;
    })
    .catch((err: any) => {});
});

</script>
<style scoped>
.item {
  margin-top: 10px;
  margin-right: 40px; 
}
</style>

2.添加路由的 name: ‘about’,

 {
        path: '/about',
        name: 'about',
        component: () => import("@/views/About.vue"),
        meta: { title: "关于我们", icon: "Box", show: true, isFrame:true }
}
  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

great-sun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值