Element-UI el-table-column 使用slot插槽v-if數據更新後沒有渲染

原因是因爲表格是element-ui通過循環產生的,而vue在dom重新渲染時有一個性能優化機制,就是相同dom會被複用,通過key去標識一下當前行是唯一的,不許複用,就行了。

在其和其之後的一個顯示的組件上添加 :key="Math.random()"
事列:

       <el-table-column
          :label="$t('customer.name')"
          prop="name"
          :show-overflow-tooltip="true"
          v-if="showColumn('Name')"
          :sort-orders="['descending', 'ascending']"
          :key="Math.random()"
        >
          <template slot="header">
            <span>{{ $t('customer.name') }}</span>
            <span
              class="icon-wrapper"
              v-if="isSortable('customerName')"
              @click="handleSortTable('customerName')"
            >
              <svg-icon
                iconClass="caret-bottom"
                v-if="sortProp === 'customerName' && sortOrder === 'ascending'"
              />
              <svg-icon
                iconClass="caret-top"
                v-else-if="
                  sortProp === 'customerName' && sortOrder === 'descending'
                "
              />
              <svg-icon v-else iconClass="caret-null" />
            </span>
          </template>
..............................

參考博客

Element-UI el-table-column 使用slot插槽 v-if 報錯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章