tiantingrui / daily-harvest

记录每日收获
MIT License
2 stars 0 forks source link

vue 父组件强制刷新子组件 #32

Open tiantingrui opened 2 years ago

tiantingrui commented 2 years ago

方法一: 使用 v-if 的特性(销毁并且重绘)可以强制刷新子组件

<el-table-column label="启停">
          <template #default="scope">
            <disabled-switch
              v-if="forceRefresh"
              :value="scope.row.allowWarn"
            />
          </template>
        </el-table-column>

async getTableData() {
      this.loading = true
      this.forceRefresh = false
      const params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      const rst = await this.$api.riskControlCenter.getAlarmSettingsList(params)
      this.loading = false
      const { list, totalCount } = rst
      this.tableData = [...list]
      this.total = totalCount
      this.$nextTick(() => {
        this.forceRefresh = true
      })
    },
tiantingrui commented 2 years ago

方法二: 使用this.$forceUpdate强制重新渲染