我试图直接导出一个对象,但我没有得到我想要的结果;
const cmd = {
name: "testFunc",
desc: "Test",
execute(name, args) {
console.log("Test ()");
}
}
export {cmd}我按以下方式进口;
import(`./commands/${file}`).then(cmd => {
console.log(cmd.cmd.name);
})但是我宁愿只做cmd.name,而不是cmd.cmd.name。
发布于 2020-02-01 15:11:48
不要导出对象,而是使用单独的命名导出:
export const name = testFunc";
export const desc = "Test";
export function execute(name, args) {
console.log("Test ()");
}或者,将导入语句更改为使用析构:
import(`./commands/${file}`).then(({cmd}) => {
console.log(cmd.name);
})https://stackoverflow.com/questions/60018135
复制相似问题