如何使用方法更新vuejs组件数据?
How to update vuejs component data with methods?
我正在尝试使用一种方法重新初始化组件的一些输入数据。然而,我在编译这段代码时遇到错误,但我确信语法是正确的......?有人看到错误吗?或者可以解释为什么会出现此错误?
模板
<div class="text-center padder-v">
<button @click="queryReset" class="color-button">Réinitialiser les filtres</button>
</div>
剧本
export default {
data() {
return {
queryLevel: "",
queryCycle: "",
querySubject: ""
};
},
watch: {
queryLevel: {
handler() {
if (this.queryCycle != "" || this.querySubject != "") {
queryReset();
}
}
}
},
methods: {
queryReset() {
this.queryCycle = "",
this.querySubject = "",
}
} //compiling error
}
语句应该以分号结束 ;
而不是逗号 ,
export default {
data() {
return {
queryLevel: "",
queryCycle: "",
querySubject: ""
};
},
watch: {
queryLevel() {
if (this.queryCycle != "" || this.querySubject != "") {
this.queryReset(); // use `this.queryReset()`
}
}
},
methods: {
queryReset() {
this.queryCycle = ""; // Should end with semicolon
this.querySubject = ""; // Should end with semicolon
}
}
}
不明白为什么你在末尾使用逗号而不是“;”
this.queryCycle = "",
this.querySubject = "",
我正在尝试使用一种方法重新初始化组件的一些输入数据。然而,我在编译这段代码时遇到错误,但我确信语法是正确的......?有人看到错误吗?或者可以解释为什么会出现此错误?
模板
<div class="text-center padder-v">
<button @click="queryReset" class="color-button">Réinitialiser les filtres</button>
</div>
剧本
export default {
data() {
return {
queryLevel: "",
queryCycle: "",
querySubject: ""
};
},
watch: {
queryLevel: {
handler() {
if (this.queryCycle != "" || this.querySubject != "") {
queryReset();
}
}
}
},
methods: {
queryReset() {
this.queryCycle = "",
this.querySubject = "",
}
} //compiling error
}
语句应该以分号结束 ;
而不是逗号 ,
export default {
data() {
return {
queryLevel: "",
queryCycle: "",
querySubject: ""
};
},
watch: {
queryLevel() {
if (this.queryCycle != "" || this.querySubject != "") {
this.queryReset(); // use `this.queryReset()`
}
}
},
methods: {
queryReset() {
this.queryCycle = ""; // Should end with semicolon
this.querySubject = ""; // Should end with semicolon
}
}
}
不明白为什么你在末尾使用逗号而不是“;”
this.queryCycle = "", this.querySubject = "",