vue使用antd表格组件进行跳转

vue使用Antd表格组件跳转的两种方式


在这里插入图片描述

第一种:点击行进行跳转

点击行内的任何一处都可以进行跳转,直接上代码;

<template>
  <div class="home">
    <div style="background:#ECECEC; padding:30px">
      <a-card :bordered="false" style="width: 100%">
        <a-table :columns="Projectcolumns" :data-source="Projectdata" :bordered='true' :customRow='toAbout'>
          <template slot="operation" slot-scope="text, record">详情</template>
        </a-table>
      </a-card>
    </div>
  </div>
</template>

<script>
const Projectcolumns = [
  { 
    title: '名字', 
    dataIndex: 'pname', 
    key: 'pname', 
    align:'center', 
  },{ 
    title: '年龄', 
    dataIndex: 'age', 
    key: 'age', 
    width:'20%',
    align:'center',
  },{ 
    title: '操作', 
    dataIndex: 'operation', 
    key: 'operation', 
    width:'20%',
    align:'center',
    scopedSlots: { customRender: 'operation' },// 直接对应插槽名为operation的模板
  }
];

const Projectdata = [];

for (let i = 0; i < 100; i++) {
  Projectdata.push({
    key: i.toString(),
    pname: `Edrward ${i}`,
    age: 32,
  });
}

export default {
  name: 'Home',
  components: {
    // HelloWorld
  },
  data() {
    return {
      Projectdata,
      Projectcolumns,
    };
  },
  methods: {
      toAbout(record, index){
        return {
            on: {
               click: () => {
                    console.log(record,index)
                    this.$router.push({ 
                        path:'/about'
                    })
                  }
                }
            }
      },
    },
}
</script>

第二种:点击详情进行跳转

代码如下

<template>
  <div class="home">
    <div style="background:#ECECEC; padding:30px">
      <a-card :bordered="false" style="width: 100%">
        <a-table :columns="Projectcolumns" :data-source="Projectdata" :bordered='true' :customRow='toAbout'>
          <template slot="operation" slot-scope="text, record">
            <router-link :to="{path:'/about'}"></router-link>
          </template>
        </a-table>
      </a-card>
    </div>
  </div>
</template>

<script>
const Projectcolumns = [
  { 
    title: '名字', 
    dataIndex: 'pname', 
    key: 'pname', 
    align:'center', 
  },{ 
    title: '年龄', 
    dataIndex: 'age', 
    key: 'age', 
    width:'20%',
    align:'center',
  },{ 
    title: '操作', 
    dataIndex: 'operation', 
    key: 'operation', 
    width:'20%',
    align:'center',
    scopedSlots: { customRender: 'operation' },// 直接对应插槽名为operation的模板
  }
];

const Projectdata = [];

for (let i = 0; i < 100; i++) {
  Projectdata.push({
    key: i.toString(),
    pname: `Edrward ${i}`,
    age: 32,
  });
}

export default {
  data() {
    return {
      Projectdata,
      Projectcolumns,
    };
  },
  methods: {}
}
</script>
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值