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 }) }