【发布时间】:2020-08-16 20:51:56
【问题描述】:
我正在学习 vuex。在将一些方法迁移到 vuex 操作后,我遇到了一个奇怪的问题。
在我将一些东西迁移到 vuex 并且我在组件 ...mapGetters 和 ...mapActions 中实现之前,我在一个运行良好的组件中遇到了这个错误。
错误是[Vue warn]: Property or method "isVisible" is not defined on the instance but referenced during render
但在我的数据中我已经声明了道具
data() {
return {
id: state.userInfo.id,
endCursor: state.userInfo.end_cursor,
nextPageLoaded: false,
isVisible: false,
isVideo: null,
url: null
}
}
<div class="modal fade show" tabindex="-1" role="dialog" v-if="isVisible">
<div class="modal-dialog">
<div class="modal-content h-100 rounded-0">
<div class="modal-header">
<button type="button" class="close mb-3 float-right" @click.prevent="closeZoomModal()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- display image -->
<img class="img-fluid w-100 h-100 img-zoom" :src="url" v-if="!isVideo">
<!-- display video -->
<div class="embed-responsive embed-responsive-4by3 h-100" v-else>
<iframe class="embed-responsive-item h-100" :src="url" title=""></iframe>
</div>
</div>
</div>
</div>
</div>
这发生在用户单击 home 组件以搜索 ome 数据并加载引发错误的结果组件之后。
我该如何解决?错误是由...mapGetters 或...mapActions 引起的吗?
【问题讨论】:
-
你能分享你的
..mapGetters代码部分吗? -
@SajibKhan 我已经调试了代码,我发现问题不在于
...mapGetters,问题在于data(),我需要使用映射的getter。对此有何帮助? -
...mapGetters应该在computed内部使用,而不是在data内部使用! -
isVisible在模板中不可用的原因是因为data函数中断,因为state未定义。因此它的内容在模板中都不可用,并且在模板中遇到的第一个未知道具恰好是isVisible。
标签: vue.js