原因:因為父組件有緩存等因素,子組件創建后沒有釋放,傳入參數無效,使用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 }) }