vue表格-增加/删除一行

表格增加一行或者减少一行

xx.vue

<template>
  <div>
    <el-table :data="linkData" style="width:70%;" max-height="250">
      <el-table-column
        prop="linkName"
        label="链接名称"
        align="center"
        show-overflow-tooltip
        min-width="30%"
      >
        <template slot-scope="scope">
          <el-input size="small" v-model="linkData[scope.$index].linkName" placeholder="请填写链接名称"></el-input>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        show-overflow-tooltip
        min-width="70%"
        prop="href"
        label="链接地址"
        type="url"
      >
        <template slot-scope="scope">
          <el-input size="small" v-model="linkData[scope.$index].href"></el-input>
        </template>
      </el-table-column>
      <el-table-column
        prop="change"
        label="操作"
        align="center"
        show-overflow-tooltip
        min-width="16%"
      >
        <template slot-scope="scope">
          <!-- <el-button v-if="scope.$index === 0" @click="add" circle el-icon-plus>添加</el-button> -->
          <el-button
            size="small"
            v-if="scope.$index === 0"
            @click="add"
            type="primary"
            icon="el-icon-plus"
            circle
          ></el-button>
          <el-button
            size="small"
            v-if="scope.$index > 0"
            @click="deleteRow(scope.$index)"
            type="danger"
            icon="el-icon-close"
            circle
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data () {
    return {
      linkData: [
        {
          linkName: null,
          href: null
        }
      ]
    }
  },
  components: {
  },
  mounted (linkData) {
    console.log(linkData)
  },
  props: {
    linkData: {
      type: Object,
      default: null
    }
  },
  methods: {
    /**
    * 添加一行规格
    */
    add () {
      if (this.linkData.length >= 5) {
        this.$message.error('最多添加5个链接')
        return
      }
      this.linkData.push({ linkName: '', href: '' })
    },
    /**
     * 删除一行规格
     */
    deleteRow (index) {
      this.linkData.splice(index, 1)
    }
  }
}
</script>
<style lang="scss">
</style>
       
自定义table表头

在这里插入图片描述


<el-table-column prop="visitor" label="访客数" v-if="isVisible2" sortable>
        <!-- <template slot="header" :slot-scope="{ column, $index }"> -->
        <template slot="header">
          <span>访客数</span>
          <el-popover
            placement="top"
            width="200"
            trigger="hover"
            content="统计时间内,商品详情页被访问的去重人数,一个人在统计时间范围内访问多次记为一人。注意,若顾客浏览商品列表并直接加购、下单,未进入商详页,则不会记入该商品的访客数,此时,会出现商品的访客数小于支付人数的情况"
          >
            <i class="el-icon-question" slot="reference"></i>
          </el-popover>
        </template>
      </el-table-column>

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值