【发布时间】:2021-11-28 09:55:55
【问题描述】:
我正在与BootstrapVue 合作。
我需要 emit 为我的 parent.vue 赋值 - 但我的代码行 this.$emit('info', this.hide); 不起作用。
如果我console.log(this.hide) 在这种情况下我的值是正确的false,否则如果我的if-statement 是正确的我得到它true。
这里有什么错误?
我 child.vue 的脚本:
data(){
return {
hide: true,
}
}
mounted() {
if (statement) {
if(some statement) {
//do something
} else {
this.hide = false;
console.log(this.hide); //HERE I GET CORRECT VALUE
this.$emit('info', this.hide); //THIS DOESNT WORK
}
}
}
它应该如何在我的 parent.vue 中工作:
<template>
<div @info="info">
<div> //THIS DIV SHOULD BE SHOWN IF this.hide = false
</div>
<div> //THIS DIV SHOULD BE SHOWN IF this.hide = true
</div>
</div>
</template>
【问题讨论】:
-
你在 parent.vue 中有
@info处理程序吗? -
是的.. 我的 parent.vue 中有 @info="info"
-
更新了我的问题,向您展示我需要做什么..
-
你的子组件叫什么名字?
-
父:App.vue / 子:login.vue
标签: javascript vue.js vuejs2 bootstrap-vue emit