【发布时间】:2019-10-18 02:31:53
【问题描述】:
当 B 组件完成加载后,我通过 EventBus 向 A 组件发送一个“发射”事件。
并且当从A组件接收到的事件为“on”时,它会将特定数据的值更改为true。
该值在computed中注册,如果值为true,则只能与“a tag”一起使用。
但实际上值变为true但点击事件仍然返回“return false;”
如何让点击事件在 VueJS 中动态表现?
B 组件
...
this.$EventBus.$emit("Loading");
...
一个组件
<template>
<a href="javascript:void(0)" @click="completed ? btnFinish : 'return false;'">Complete</a>
</template>
<script>
data() {
return {
loading: false,
}
},
mounted() {
this.$EventBus.$on('Loading', ()=>{
this.loading = true;
});
},
computed: {
completed() {
return this.loading
}
}
</script>
【问题讨论】:
-
你怎么知道'returns "return false;"'?
btnFinish是什么? -
btnFinish()是一个方法来操作。如果“return false;”,点击时什么都不会发生,但是如果console.log()作为方法工作,默认显示console.log()。所以,即使this.loading改成true,点击事件依然返回“return false;”。
标签: javascript vue.js