用vue+elementui寫后台時,實現頁面間彈出框的form表單,使用父子組件間傳值
父組件向子組件傳值,父組件向子組件傳值是通過props傳遞的
子組件向父組件改變值時,通過$emit改變
父組件中:
import ExitProductCreate from '../dialog/ExistProductCreate'
//前面使用props傳值,后面捅過$emit改變父組件間的值
<ExitProductCreate :dialogVisible="dialogVisible1" v-on:changeFather="showEpcre()"></ExitProductCreate>
export default {
components{
ExistProductCreate
}
data() {
return {
dialogVisible1 : false
}
}
子組件中
html中: //通過點擊取消按鈕,關閉彈出框,改變父組件中的值 <el-button @click="cancle">取消</button> js中: export default { props: {// 接受父組件傳遞過來的props dialogVisibe:Boolean } // 監聽父組件穿過來的值 watch: { dialogVisible: function(newItemVal, oldItemVal) { this.dialogVisible1 = newItemVal; }, methods:{ cancle(){ this.dialogVisible1 = false; this.$emit("changeFather","false") } }