对于一个简单的演示,我想反转我在Vue的数据属性中定义的布尔值.js实例.
我try 的是:
<button @click="!spanVisible" type="button">Toggle</button>
和
<button @click="(!spanVisible)" type="button">Toggle</button>
我想避免写一个单独的方法,或者在我的v-on:click="":spanVisible ? !spanVisible : !spanVisible
中有类似的东西,因为它只是多余的.
So now my questions mostly are: Why doesn't the direct inverting work? What other possibility do I have to keep it short 和 simple?
edit:
我现在发现的最短可能的变化是使用spanVisible = !spanVisible
,但不确定这是否是可用的最简洁的版本.
SOLUTION:
我找到的最佳解决方案是@Sombriks在 comments 中提出的: