gpt4 book ai didi

javascript - 在Vue中为===相等分配右值

转载 作者:行者123 更新时间:2023-12-01 16:09:46 24 4
gpt4 key购买 nike

我的代码很简单:

<b-button
v-for="t in tags" :key="t"
:to="{ name: 'tag', params: { tag: t } }"
:pressed.sync="t === tag"
>#{{t}}</b-button>

props: {
tag: String,
},
但它失败了:
 SyntaxError: Assigning to rvalue (1:341)
当我删除此比较时,它会起作用:
:pressed.sync="t === tag"
如果有 "t = tag"我会理解的。甚至 Idea 都认为我的代码很好,当我使用 "t == tag" 时它会提示.

最佳答案

删除 .sync修饰符。

.sync Modifier

Note that v-bind with the .sync modifier does not work with expressions (e.g. v-bind:title.sync="doc.title + '!'" is invalid). Instead, you must only provide the name of the property you want to bind, similar to v-model.


按钮组件正在尝试将按下状态写回您提供的表达式。这就像尝试
(a === b) = c
这会引发无效的分配错误。

关于javascript - 在Vue中为===相等分配右值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63458514/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com