vue 強制刷新子組件


原因:因為父組件有緩存等因素,子組件創建后沒有釋放,傳入參數無效,使用v-if的特性(銷毀和重建)可以強制刷新子組件

    <el-drawer
      ref="detailTable"
      :title="detailTitle"
      :append-to-body="true"
      :visible.sync="dialogDetailFormVisible"
      direction="ltr"
      :wrapper-closable="false"
      size="90%"
    >
      <div class="el-drawer__body">
        <el-row :gutter="10">
          <el-col :span="22" :offset="1">
            <ProjectMileStone v-if="forceRefresh" :project-id="projectId" />
          </el-col>
        </el-row>
      </div>
    </el-drawer>
toView(row) {
      this.forceRefresh = false
      this.projectId = row.projectId
      this.detailTitle = row.projectName
      // 強制刷新子組件
      this.$nextTick(() => {
        this.forceRefresh = true
        this.dialogDetailFormVisible = true
      })
    }

 


免責聲明!

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



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