ANTD-Vue 可编辑table(v-model配合table使用)

<template>
  <div class="newDTable">
    <h2>ANTD-Vue table配合v-model使用</h2>
    <!-- 
             属性作用
             columns       //表头
             data-source   //数据
             slot          //插槽名
             slot-scope    //传递的参数
    -->
    <a-table :columns="columns" :data-source="data">
      <span slot="name" slot-scope="name, record, index">
        <!-- 
          slot-scope="name, record, index"
          name表示本项内容对应的字段值value,record的值是object,表示的是这一行数据的全部内容,index表示当行索引
         -->
        <!-- 
            此时v-model绑定data[index].name的是对应的数据,实现双向绑定
         -->
        <input type="text" v-model="data[index].name" />
      </span>
      <span slot="age" slot-scope="age, record, index">
        <input type="text" v-model="data[index].age" />
      </span>
      <span slot="address" slot-scope="age, record, index">
        <input type="text" v-model="data[index].address" />
      </span>
      <span slot="tags" slot-scope="tags, record, index">
        <input type="text" v-model="data[index].tags" />
      </span>
      <span slot="action" slot-scope="action, record, index">
        <button @click="clickChangeInp">点击查看改变后的数据</button>
      </span>
    </a-table>
  </div>
</template>
<script>
const columns = [
  {
    dataIndex: "name",
    key: "name",
    title: "name",
    scopedSlots: { customRender: "name" }, //使用 columns 时,可以通过该属性配置支持 slot-scope 的属性,如 scopedSlots: { customRender: 'XXX'}
  },
  {
    title: "Age",
    dataIndex: "age",
    key: "age",
    scopedSlots: { customRender: "age" },
  },
  {
    title: "Address",
    dataIndex: "address",
    key: "address",
    scopedSlots: { customRender: "address" },
  },
  {
    title: "Tags",
    key: "tags",
    dataIndex: "tags",
    scopedSlots: { customRender: "tags" },
  },
  {
    title: "Action",
    key: "action",
    dataIndex: "action",
    scopedSlots: { customRender: "action" },
  },
];

export default {
  name: "newDTable",
  data() {
    return {
      data: [
        {
          key: "1",
          name: "",
          age: "",
          address: "",
          tags: "",
        },
        {
          key: "2",
          name: "",
          age: "",
          address: "",
          tags: "",
        },
      ],
      columns,
    };
  },
  methods: {
    clickChangeInp() {
      console.log(this.data, "改变后的数据");
    },
  },
};
</script>

控制台效果
在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值