使用map循環對每一個字段進行驗證
let fieldsToValidate = ['username', 'password', 'gender', 'email']; let _self = this; Promise.all(fieldsToValidate.map(item => { let p = new Promise(function (resolve, reject) { _self.$refs['form'].validateField(item, (error) => { resolve(error) }) }); return p; })).then((data) => { console.info(data) // data 裏是各個字段的驗證錯誤信息, 若是爲空串則認爲驗證經過, 若是數組裏全爲空串則全部驗證經過 // 判斷data 裏是否全是空串 })