Problem: the error message is that a red wavy line appears in the editing of vscade. When the mouse is placed, it will prompt: parsing error: await is a reserved word. Parsing error: await is a reserved word, indicating that the editor does not recognize it and takes it as a keyword
Because an async keyword is added to the function outside the form verification, you want to write synchronization code in the callback function, but an error is reported.
// save
async save() {
this.$refs.form.validateForm((valid) => {
if (valid) {
// The purpose of adding await is to wait for the save to complete before refreshing the list
await /* this async reports an error */ this.saveRecord()
this.$emit('closeModal')
this.reset()
}
})
}
After modification:
save() {
// The async should be defined in front of the callback function (anonymous function) at this point.
// The external function and the callback function form two separate scopes.
// The function defined externally and the callback function form two block scopes,
// At this point, await and aysnc are not in the same scope, so they cannot be paired and an error is reported
this.$refs.form.validateForm(async (valid) => {
if (valid) {
// The purpose of adding await is to wait for the save to complete before refreshing the list
await /* No error is reported here for async */ this.saveRecord()
this.$emit('closeModal')
this.reset()
}
})
}
Summary: if you want to write synchronization code inside the callback function, you need to put the async keyword in front of the callback function to make async and await in the same scope
Read More:
- [Solved] Vue-vscode Error: Parsing error: Unexpected reserved word ‘await‘.
- JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
- [Solved] error Component name “xxx“ should always be multi-word vue/multi-word-comp
- [Solved] 1:1 error Component name “Header“ should always be multi-word vue/multi-word
- 9:13 error Component name “home“ should always be multi-word vue/multi-word-component-names
- When using iView, report: no parsing error parsing error: x-invalid-end-tag solution
- [Solved] vue error: error Component name “School“ should always be multi-word vue/multi-word-component-names
- [Solved] Vue eslint Error: Component name “*****“ should always be multi-word
- [Solved] Component name “login“ should always be multi-word.
- [Solved] ESlint Create New File Error: Component name “Home” should always be multi-word.
- Parsing error:x-invalid-end-tag [How to Solve]
- OTS parsing error: invalid version tag [How to Solve]
- [Solved] Parsing error: No Babel config file detected for XXX
- [Solved] Vue Error: Parsing error:No Babel config file detected for xxx
- [Solved] Eslint Error: Parsing error: x-invalid-end-tag
- [Solved] vue Project Error: react lazy eslint error Parsing error: Unexpected token import
- [Solved] ESLint: Parsing error: Unexpected token(prettier/prettier)
- [Solved] VUE D:\project\vueProject\vue-02\src\components\hello.vue 5:5 error Parsing error: x-invalid-end-tag
- [Solved] Vue Error: Parsing error: No Babel config file detected for
- [Solved] Vue Error: Parsing error: No Babel config file detected for /Users/Usename/xxx…