最近用了父子組件求晶,在子組件發(fā)送請(qǐng)求,只是首次發(fā)送衷笋,關(guān)閉子組件芳杏,再次打開(kāi),就不請(qǐng)求了,百度了一下爵赵,找到了方法吝秕,這里記錄一下。
<template>
<div class="pageContainer">
<el-button type="primary" @click="handleCreate">
創(chuàng)建
</el-button>
<Child :key="timer"></Child>
</div>
</template>
import Child from "@/components/child";
components: {
Child
},
data() {
return {
timer:null
}
},
methods: {
handleCreate() {
this.timer = new Date().getTime();
// 也可以處理其他事件
},
}
這里在子組件加了一個(gè)key,相當(dāng)于每一次點(diǎn)擊空幻,都刷新一次子組件烁峭。