我从 MySQL 数据库获取数据,其形式为“1”和“0”,分别代表布尔值 true 和 false。这些值按以下方式在 vue 组件中设置:
data(){
return {
form : {
attribute_1 : "1", //attribute 1 is true
attribute_2 : "0", //attribute 2 is false
attribute_3 : "1", //attribute 3 is true
}
}
}
Run Code Online (Sandbox Code Playgroud)
为了维护双向绑定,我当前使用计算属性,如下所示:
attribute1: {
get(){
return this.form.attribute_1 == "1" ? true : false ;
},
set(newValue){
this.form.attribute_1 = newValue ? "1" : "0";
}
},
attribute2: {
get(){
return this.form.attribute_2 == "1" ? true : false ;
},
set(newValue){
this.form.attribute_2 = newValue ? …Run Code Online (Sandbox Code Playgroud)