Element-ui table 異步加載特定列的處理方案


異步加載

典型應用: 先展示所有文章信息,每一行增加一個鏡像字段,如: _async_label ,請求成功后更新該字段內容,失敗則更新為特定字符,如 '-' 。

核心代碼

1 <el-table-column label="標簽"
2                 min-width="100"
3                 align="center">
4 <template slot-scope="scope">
5     <span>{{ scope.row._async_label }}</span>
6 </template>
7 </el-table-column>

 

 1 methods: {
 2   getList() {
 3     this.listLoading = true
 4     this.fetchData(this.listQuery)
 5     .then(response => {
 6       let tablist = response.data.items
 7       let total = response.data.total
 8       // 異步顯示文章標簽
 9       tablist.forEach(item => {
10         item._async_label = ''
11       })
12       this.list = tablist
13       this.total = total
14       this.getLabel()
15       // 這里 loading 結束,頁面上可以看到表格了
16       this.listLoading = false
17     })
18     .catch(err => {
19       this.$notify.warning({
20         message: err || '未獲取到相關信息,請刷新頁面或稍候再試',
21         duration: 3 * 1000,
22       })
23       this.listLoading = false
24     })
25   },
26   // 獲取 文章標簽
27   getLabel(){
28     this.list.forEach(item => {
29       getArticleLabelApi(item.articleId)
30       .then(resp => {
31         item._async_label = resp.data.val
32       })
33       .catch(()=>{
34         item._async_label = '-'
35       })
36     })
37   },
38 }

 


免責聲明!

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



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