有没有办法让 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/