el-table-column v-if條件渲染報錯h.$scopedSlots.default is not a function


我們在實際項目中經常會遇到el-table-column條件渲染出現報錯的情況

報錯內容: h.$scopedSlots.default is not a function

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

代碼示例如下:

添加 :key="Math.random()"

<el-table :data="tableData" style="width: 100%;">
   <el-table-column type="selection" width="45"></el-table-column>
   <el-table-column prop="applyTime" label="日期" min-width="150" :key="Math.random()"></el-table-column>
   <el-table-column prop="productName" label="產品名稱" min-width="120" :key="Math.random()"></el-table-column>
   <el-table-column prop="orderNo" label="訂單號" min-width="120" :key="Math.random()"></el-table-column>
   <el-table-column prop="amount" label="金額" width="150" :key="Math.random()"></el-table-column>
   <el-table-column prop="remark" label="備注" width="150" :key="Math.random()"></el-table-column>
   <el-table-column fixed="right" label="操作" width="200" :key="Math.random()" v-if="currentTab === 'xxx'">
     <template slot-scope="{row}">
       <el-button type="text" size="small">查看詳情</el-button>
       <el-button type="text" size="small">編輯</el-button>
     </template>
   </el-table-column>
</el-table>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM