jeecg-boot前端学习总结(一)

在这里插入图片描述
这个控件样式的制作和使用
首先是一个表格

   <a-table
          :columns="columns"
          :dataSource="data"
          :pagination="false"
        >  </a-table>

表格行定义

    columns: [
          {
            title: '成员姓名',
            dataIndex: 'name',
            key: 'name',
            width: '20%',
            scopedSlots: { customRender: 'name' }
          },
          {
            title: '工号',
            dataIndex: 'workId',
            key: 'workId',
            width: '20%',
            scopedSlots: { customRender: 'workId' }
          },
          {
            title: '所属部门',
            dataIndex: 'department',
            key: 'department',
            width: '40%',
            scopedSlots: { customRender: 'department' }
          },
          {
            title: '操作',
            key: 'action',
            scopedSlots: { customRender: 'operation' }
          }
        ],

然后是插槽遍历

  <template v-for="(col, i) in ['name', 'workId', 'department']" :slot="col" slot-scope="text, record, index">
            <a-input
              :key="col"
              v-if="record.editable"
              style="margin: -5px 0"
              :value="text"
              :placeholder="columns[i].title"
              @change="e => handleChange(e.target.value, record.key, col)"
            />
            <template v-else>{{ text }}</template>
          </template>
 <template slot="operation" slot-scope="text, record, index">
            <template v-if="record.editable">
              <span v-if="record.isNew">
                <a @click="saveRow(record.key)">添加</a>
                <a-divider type="vertical" />
                <a-popconfirm title="是否要删除此行?" @confirm="remove(record.key)">
                  <a>删除</a>
                </a-popconfirm>
              </span>
              <span v-else>
                <a @click="saveRow(record.key)">保存</a>
                <a-divider type="vertical" />
                <a @click="cancel(record.key)">取消</a>
              </span>
            </template>
            <span v-else>
              <a @click="toggle(record.key)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="是否要删除此行?" @confirm="remove(record.key)">
                <a>删除</a>
              </a-popconfirm>
            </span>
          </template>

新增成员按钮

在这里插入代码片
  <a-button style="width: 100%; margin-top: 16px; margin-bottom: 8px" type="dashed" icon="plus" @click="newMember">新增成员</a-button>

新增方法如下

   newMember () {
        this.data.push({                      //数据源 增加一个数组 ,按照key值来,动态使用的时候每次key给+1
          key: '-1',
          name: '',
          workId: '',
          department: '',
          editable: true,                //表示是否可以编辑
          isNew: true                
        })
      },

点击新增按纽的效果
在这里插入图片描述
编辑方法

 toggle (key) {
        let target = this.data.filter(item => item.key === key)[0]        //筛选出 数据源 key 等于传入的key的第一个值
        target.editable = !target.editable                       //设置为可编辑
      },

删除方法

 remove (key) {
        const newData = this.data.filter(item => item.key !== key)  //把 传入的key值剔除
        this.data = newData                                      //赋予数据源
      },

添加方法

  saveRow (key) {
        let target = this.data.filter(item => item.key === key)[0]
        target.editable = false
        target.isNew = false
      },

取消方法

 cancel (key) {
        let target = this.data.filter(item => item.key === key)[0]
        target.editable = false
      },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值