zoukankan      html  css  js  c++  java
  • 【 iview 实践指南】之如何优雅地在"Table"中嵌套"Input"(代码篇)

    iview 版本 3.2.0 +
    template 部分:

    <template>
      <div>
        <Table class="data-manage-table"
               border
               :disabled-hover="true"
               :columns="columns"
               :data="datalist">
          <template slot-scope="{ row, index }" slot="result">
            <Input v-model="tempDatalist[index]['result']"/>
          </template>
          <template slot-scope="{ row, index }" slot="remark">
            <Input v-model="tempDatalist[index]['remark']"/>
          </template>
        </Table>
      </div>
    </template>

    data 部分:

    data () {
      return {
        columns: [
          { winWidth: 120, align: 'center', title: 'KPI指标', key: 'target' },
          {  140, align: 'center', title: '月度权重(%)', key: 'weight' },
          { winWidth: 80, align: 'center', title: '考核结果', slot: 'result' },
          { winWidth: 80, align: 'center', title: '备注', slot: 'remark' },
        ],
        datalist: [
          { target: '指标1', weight: '10', result: '', remark: '', },
          { target: '指标2', weight: '20', result: '', remark: '', },
          { target: '指标3', weight: '30', result: '', remark: '', },
          { target: '指标4', weight: '40', result: '', remark: '', },
        ],
        tempDatalist: []
      }
    },
    created () {
      this.tempDatalist = cloneObj(this.datalist)
    }

    iview 版本 3.2.0 -

    template 部分:

    <template>
      <div>
        <Table class="data-manage-table"
               border
               :disabled-hover="true"
               :columns="columns"
               :data="datalist">
        </Table>
      </div>
    </template>

    data 部分:

    data () {
     let vm = this;
    return { columns: [ { winWidth: 120, align: 'center', title: 'KPI指标', key: 'target' }, { 140, align: 'center', title: '月度权重(%)', key: 'weight' }, { winWidth: 80, align: 'center', title: '考核结果', key: 'result', render: (h, params) => { return h('div', [ h('Input', { props: { value: vm.datalist[params.index].result }, on: { input: function (event) { vm.$set(vm.tempDatalist[params.index], 'result', event) } } }) ]) } }, { winWidth: 80, align: 'center', title: '备注', key: 'remark', render: (h, params) => { return h('div', [ h('Input', { props: { value: vm.datalist[params.index].remark }, on: { input: function (event) { vm.$set(vm.tempDatalist[params.index], 'remark', event) } } }) ]) } }, ], datalist: [ { target: '指标1', weight: '10', result: '', remark: '', }, { target: '指标2', weight: '20', result: '', remark: '', }, { target: '指标3', weight: '30', result: '', remark: '', }, { target: '指标4', weight: '40', result: '', remark: '', }, ], tempDatalist: [] } }, created () { this.tempDatalist = cloneObj(this.datalist) }

    cloneObj:

    // 克隆对象
    export const cloneObj = function (obj) {
      let o
      if (typeof obj === 'object') {
        if (obj === null) {
          o = null
        } else {
          if (obj instanceof Array) {
            o = []
            for (let i = 0, len = obj.length; i < len; i++) {
              o.push(cloneObj(obj[i]))
            }
          } else {
            o = {}
            for (let j in obj) {
              o[j] = cloneObj(obj[j])
            }
          }
        }
      } else {
        o = obj
      }
      return o
    }
    author:Lik
    Endeavoring to powerless, struggling to move yourself.
  • 相关阅读:
    Java并发编程基本概念
    详解TCP:顺序和丢包问题
    详解TCP:三次握手、四次挥手
    使用DockerFile构建运行GoWeb
    Go之Gorm和BeegoORM简介及配置使用
    Nginx WebUI管理
    Kibana配置nginx反代并本地ca加密nginx
    07 . ELK Stack7.2一键多机部署脚本
    腾讯蓝鲸自动化运维平台简介部署及常见报错解决
    Go操作Redis
  • 原文地址:https://www.cnblogs.com/likwin/p/10572596.html
Copyright © 2011-2022 走看看