cnpm i babel-plugin-await-add-trycatch -D
//babel.config.js
module.exports = {
presets: ['@vue/cli-plugin-babel/preset'],
plugins: [
[
require('babel-plugin-await-add-trycatch'),
{
exclude: [], // 默认值 []
include: [], // 默认值 ["src"]
printErrorInfo: false // 默认值 true
}
]
]
}
// 示例
async function fn() {
await new Promise((resolve, reject) => {
reject('failure')
})
}
fn()