[英]Vue 3: How to call function from another function in the same mutations.js in Vuex store
In my mutations.js file, I happen to have one function calling another function in the same file.在我的 mutations.js 文件中,我碰巧有一个 function 在同一文件中调用另一个 function。 Here's my sample code example:
这是我的示例代码示例:
export default {
async addQuestionAnswer(state, payload) {
alert(payload);
this.updateSubjects(state);
alert("This is never reached");
},
updateSubjects(state) {
alert("This is never reached");
},
}
Does anyone know how to call the updateSubjects function from the addQuestionAnswer function?有谁知道如何从 addQuestionAnswer function 调用 updateSubjects function? I've checked my console.log and found this error:
我检查了我的 console.log 并发现了这个错误:
Uncaught (in promise) TypeError: _this.updateSubjects is not a function
Thanks @kissu, I've found the solution to my problem based on the console.log error I've posted with your suggestion.谢谢@kissu,我根据你的建议发布的 console.log 错误找到了解决我的问题的方法。 Thanks.
谢谢。 I added this to my mutations.js file:
我将其添加到我的 mutations.js 文件中:
import store from '../store';
Then I changed this:然后我改变了这个:
this.updateSubjects(state);
To this:对此:
store.commit("updateSubjects");
And it works: :-)它有效::-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.