欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

element表格變化后自動刷新的兩種方案

 更新時間:2023年04月28日 10:40:23   作者:NoBug.  
本文主要介紹了element表格變化后自動刷新的兩種方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

方案一:

在table上加上:key="Math.random()",但是這種方法需要觸發(fā)熱更新才會刷新數(shù)據(jù),比如保存

<el-table :key="Math.random()" :data="goodsList" style="width: 100%">
    <el-table-column label="ID" width="180">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="商品名" width="180">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #default>
            <div>name: {{ scope.row.name }}</div>
          </template>
          <template #reference>
            <el-tag>{{ scope.row.name }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="圖片" width="180">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <span style="margin-left: 10px">...</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="價格" width="180">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <span style="margin-left: 10px">{{ scope.row.price }}</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button size="small" @click="handleEdit(scope.$index, scope.row)">
          Edit
        </el-button>
        <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">
          Delete
        </el-button>
      </template>
    </el-table-column>
  </el-table>

方案二:

定義成響應(yīng)式數(shù)據(jù)

如果定義成 const goodsList = [ ] 是不會自動刷新的

定義成 const goodsList = ref([ ]) 就行

到此這篇關(guān)于element表格變化后自動刷新的兩種方案的文章就介紹到這了,更多相關(guān)element表格自動刷新內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論