vue + element-ui 动态表单 动态表格渲染问题

8 篇文章 0 订阅
6 篇文章 0 订阅

在开发动态表单和动态表格的时候,更改某些条件(v-if 等等)进行重新渲染时候,元素复用出现渲染问题

vue element传的值报_self.$scopedSlots.default is not a function

 

源码

<el-table
        ref="table"
        class="table szq-table"
        border
        :key="inspectionType"
        :url="asyncTable.url"
        async-type="post"
        tooltip-effect="dark"
        height="100%"
        style="width: 100%"
        :json-reader="asyncTable.asyncResponseReader"
        :params="asyncTable.params"
        :ajax-promise="asyncTable.promise"
        @load-success="loadSuccess"
        @selection-change="selectionGrid"
      >
        <div slot="empty" class="emptyTable">
          <div>
            <img src="../../../assets/images/noInfo.png" alt>
          </div>
          <p v-if="noInfoOnOff">{{ $t('noData') }}</p>
          <p v-if="noSearchDataRule">{{ $t('noSearchDataRule') }}</p>
        </div>
        <template v-for="(column, index) in columns">
          <el-table-column v-if="column.type === 'selection'" :type="column.type" :width="column.width"></el-table-column>
          <el-table-column v-else-if="column.type === 'index'" :type="column.type" :label="column.label" :width="column.width"></el-table-column>
          <el-table-column v-else-if="column.prop === 'name'" :label="column.label" :prop="column.prop" :render-header="tableHead" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-button
                type="text"
                @click="jump(scope.row)"
                class="showNameBtn"
              >{{ scope.row.name }}</el-button>
            </template>
          </el-table-column>
          <el-table-column v-else-if="column.prop === 'inspectionResult'" :label="column.label" :prop="column.prop" :render-header="tableHead" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>正常</span>
            </template>
          </el-table-column>
          <el-table-column v-else-if="column.prop === 'operation'" :label="column.label" :prop="column.prop" :width="column.width" :render-header="tableHead">
            <template slot-scope="scope">
              <el-button class="is-icon" type="iconButton" size="small" :title="'巡检'" @click="inspection(scope.row)">
                <icon class="svgPt" viewBox="0 0 24 24" name="h-icon-inspection"></icon>
              </el-button>
              <el-button class="is-icon" type="iconButton" size="small" :title="'巡检历史'" @click="inspectionHistory(scope.row)">
                <icon class="svgPt" viewBox="0 0 16 16" name="h-icon-trashcan"></icon>
              </el-button>
              <el-button class="is-icon" type="iconButton" size="small" :title="'删除'" @click="del('single', scope.row)">
                <icon class="svgPt" viewBox="0 0 16 16" name="h-icon-trashcan"></icon>
              </el-button>
            </template>
          </el-table-column>
          <el-table-column v-else :label="column.label" :prop="column.prop" :render-header="tableHead" show-overflow-tooltip></el-table-column>
        </template>
      </el-table>

解决方法

1. (个人推荐)加上不同的key: 在相同的父节点下,子节点根据key值不同,重新渲染的时候不会复用元素,所以重新渲染不会出现复用问题

2. 判断条件使用 v-show

参考文档

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值