Vuejs element table 表格添加,删除

Html 部份  

<el-table :data="tableData" style="width: 100%">
                <el-table-column type="index" label="排序" min-width="20">
                </el-table-column>
                <el-table-column min-width="10">
                    <template slot-scope="scope">
                        <i class="upward-icon" onclick="moveUp(this)"></i>
                        <i class="down-icon" onclick="moveDown(this)"></i>
                    </template>
                </el-table-column>
                <el-table-column prop="activityImg" label="图片" min-width="30">
                    <template slot-scope="scope">
                        <div class="addImg" @change="changeImg(scope.$index,scope.row)">
                            <i class="iconfont icon-tianjia"></i>
                            <input type="file">
                            <span>图片尺寸为:690*247</span>
                            <img data-src="" :src="scope.row.activityImg" data-holder-rendered="true">
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="activityNumber" label="活动编号" min-width="20">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.activityNumber"></el-input>
                    </template>
                </el-table-column>
                <el-table-column prop="activityType" label="活动类型" min-width="15">
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.activityType" placeholder="请选择场景类别">
                            <el-option v-for="item in typeVal" :key="item.value" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column prop="bookbuytime" label="操作" min-width="15">
                    <template slot-scope="scope">
                        <a class="iconfont icon-yichu" v-if="!scope.row.editing" icon="iconfont icon-yichu" @click="handleDelete(scope.$index, scope.row)"></a>
                    </template>
                </el-table-column>
            </el-table>

            <div style="padding-top:20px;clear:both;overflow:hidden;">
                <a class="icon-btn act-addgood" @click="addLine"><i class="iconfont icon-tianjia" style="float: none;margin-right: 5px;"></i>添加活动</a>
                <input type="button" class="normalBtn ml10" value="保存" @click="save">
            </div>

js部份

methods:{
        addLine(){ //添加行数
            var newValue = {
                activitySort: '',
                activityImg: '',
                activityNumber: '',
                activityType: '大转盘'
            };
            //添加新的行数
            this.tableData.push(newValue);
        },
        handleDelete(index){ //删除行数
            this.tableData.splice(index, 1)
        },
        save(){
          //这部分应该是保存提交你添加的内容
          console.log(JSON.stringify(this.tableData))
        }
}

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值