JS修改后的三元操作员?
我知道JavaScript三元操作员条件吗? optiona:optionb
,现在我看到{{option}}
在vue中,行为似乎是,如果条件
保留分配为<代码>选项,否则分配为空。这是“二进制”运算符:
JS或VUE的特定内容?
实际代码:
&lt; span:class =“ {完成:todo.done}”&gt; {{todo.text}}&lt;/span&gt;
其中
done {text-note {text-decoration {text-decoration :直线; }
是一个CSS,todo.done
是布尔值。
I am aware of the JavaScript ternary operator condition? optionA : optionB
and now I am seeing {{option: condition}}
in Vue, and the behaviour seems to be that if condition
holds the assignment is option
, otherwise the assignment is empty. Is this 'binary' operator :
something general for JS or particular to Vue?
The actual code:
<span :class="{ done: todo.done }">{{ todo.text }}</span>
where
.done { text-decoration: line-through; }
is a CSS and todo.done
is a boolean.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它不是操作员,而是常规对象文字语法。 VUE
class
属性支持对象对于有条件的类列表,布尔值确定是否将键的类名称添加到列表中或省略。这种行为类似于流行
classNames
包含相同目的的软件包在React生态系统中。It's not an operator but regular object literal syntax. Vue
class
attribute supports objects for conditional class lists, where boolean value determines whether class name from a key is added to a list or omitted.This behaviour is similar to popular
classnames
package that serves the same purpose in React ecosystem.如果您想要二进制操作员,则应选择
||
。此对象语法不是特定于vue的,而是用法是:此代码在说“设置属性完成的
”对象绑定到todo.done.done
, Vue将推断为添加或不添加对象参数的类(在您的情况下,它是完成
)。If you wanted a binary operator, you should choose
||
. This object syntax is not specific to vue but the usage is: What this code is saying is "Set the attributedone
of the object bound to the class totodo.done
, and vue will infer to add or not to add the class of the object parameter (in your case it isdone
).