gpt4 book ai didi

javascript - Vue 类与字符串绑定(bind)?

转载 作者:太空宇宙 更新时间:2023-11-04 07:21:22 24 4
gpt4 key购买 nike

有没有办法让 Vue 类绑定(bind)与字符串一起使用?例如:

<div :class={open: target == 'myString'}></div>
var app = new Vue({
target: null
})

不加引号就可以了

<div :class={open: target == myString}></div>

但我收到以下警告:

[Vue warn]: Property or method "myString" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

最佳答案

尝试以下操作

var app = new Vue({
el: '#app', // the id of the div that you will apply this object on it
data : {
target: '',
myString: '',
}
})

关于javascript - Vue 类与字符串绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50252604/

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