是否有可能将这个函数不分配给变量名 shortcut
而是分配给它的内容?
if (this.commands[this.counter].shortcut) {
const shortcut = this.commands[this.counter].shortcut;
tinykeys(window, {
shortcut: (event) => {
this.followLink('https://twitter.com');
},
});
}
例如:shortcut
的值可能是一个值为 'abc' 的字符串,我想得到以下结果:
tinykeys(window, {
'abc': (event) => {
this.followLink('https://twitter.com');
},
});
答案 0 :(得分:3)
您可以使用计算属性名称。
[shortcut]: (event) => {
this.followLink('https://twitter.com');
},