javascript - Vue.js v-if 仅第一次工作
问题描述
在我的组件模板中,我正在使用 AutoDeltaSettings 组件,我只想showAuto
在组件的数据属性为 true 时才显示该组件。
<auto-delta-settings v-if="showAuto"> </auto-delta-settings>
这是 showAuto 数据属性
data () {
return {
stepWidth: STEP_WIDTH,
headerHeight: HEADER_HEIGHT,
paddingTop: PADDING_TOP,
paddingBottom: PADDING_BOTTOM,
footerHeight: FOOTER_HEIGHT,
showAuto: false
}
}
我已经在创建的钩子上注册了事件
created () {
EventBus.$on('protocol-changed', this.protocolChanged)
EventBus.$on('show-advanced-settings', this.showAdvancedSettings)
}
当发出 show-advanced-settings 事件时,我正在调用组件的 showAdvancedSettings 方法
methods: {
showAdvancedSettings (toShow) {
console.log("To Show - Before"+ this.showAuto)
this.showAuto = toShow
console.log("To Show - After"+ this.showAuto)
}
}
我通过单击按钮从另一个组件发出事件
showAdvancedSettingsModal () {
console.log('Inside advanced settings opener - Before '+ this.showAdvancedSettings)
this.showAdvancedSettings = true
console.log('Inside advanced settings opener - After '+ this.showAdvancedSettings)
EventBus.$emit('show-advanced-settings', this.showAdvancedSettings)
},
但这仅在我第一次单击按钮时才有效,在这种情况下,AutoDeltaSettings
组件显示(基本上是一个模式),当我关闭模式并再次单击按钮以显示AutoDeltaSettings
它不起作用的组件时。
解决方案
推荐阅读
- anaconda - NSIS:在 ExecDos 中访问 https 站点
- c# - 在 ASP.NET Core Web-Api 中用 Interlocked.Exchange(ref oldValue, newValue) 替换不可变数据结构是否安全
- javascript - 如何使我的脚本针对 Google 表格中的特定列?
- sql - 根据连接中使用的联合列获取正确的记录
- objective-c - 不同 Debug 和 Release 框架的环境配置 - Xcode
- c# - C#将巨大的图像读入数组
- android - 通过 API 从 Google Store 获取统计数据
- python - 数据框分组为一列
- excel - 宏来计数过滤器不同的唯一值
- visual-studio-code - 如何摆脱 Visual Studio 代码的自动格式化?