这看起来是不可能的,但是如果我将前两部分串联到变量中,代码就会停止工作。这有效:
async findImage(code)
{
const map = (value) => value.default;
return await import('images/certification/' + code + '.svg').then(map);
}
这不起作用:
async findImage(code)
{
const map = (value) => value.default;
let pathWithoutExtension = 'images/certification/' + code;
return await import(pathWithoutExtension + '.svg').then(map);
}
它说“已选择svg:错误:找不到模块'images / certification / eco_friendly.svg'”,尽管此路径正确。 怎么会呢?
我在另一个带有await的异步函数中调用此函数:
image = await this.findImage(cert.code);