The simple question of async/await

  async submitForm(formName) {
        this.$refs[formName].validate((valid) => {
            if (valid) {
                const res = await scdup(this.ruleForm);
            }
            return false;
        });
    },
    scduppromisevueawait
May.06,2022

is not an vue error, but a js error. Await can only be used in async functions. Your function is not async, and you should just add


[read teacher Ruan Yifeng's article] http://es6.ruanyifeng.com/-sharpdo...


await can only be used in async functions. You can rewrite

in this way.
async submitForm(formName) {
    this.$refs[formName].validate(async (valid) => {
        if (valid) {
            const res = await scdup(this.ruleForm);
        }
        return false;
    });
}

just make sure that validate supports promise callback

Menu