为什么写这个是错误的:
'use strict'
async example1 () {
return 'example 1'
}
async example2 () {
return 'example 2'
}
export { example1, example2 }但这是好的:
export default {
async example1 () {
return 'example 1'
},
async example2 () {
return 'example 2'
}
}这很让人困惑。我想后者也是错的。
对此有什么解释吗?
发布于 2017-08-21 14:54:11
这种行为与async或export无关。它是ES6增强对象属性的一部分:
这些措施相当于:
const foo = 123;
const a = {
foo: foo,
bar: function bar() { return 'bar'; },
baz: async function baz() { return await something(); },
};和
const foo = 123;
const a = {
foo,
bar() { return 'bar'; },
async baz() { return await something(); },
};发布于 2017-08-21 14:53:31
第一个尝试(但失败)声明多个单独的函数,而第二个尝试使用多个method definitions创建一个对象文本,然后默认导出该对象。顺便说一句,没有async关键字也是一样的。你会想要用
export async function example1() {
return 'example 1'
}
export async function example2() {
return 'example 2'
}https://stackoverflow.com/questions/45800105
复制相似问题