在我的 vue.js 应用程序中,我试图读取传递给函数的 name
的值。我相信这是一个范围问题。环顾四周,我认为这可以通过粗箭头功能来解决?
这是我用来处理更改事件的方法。有什么办法吗
async handleChange(event, name) {
console.log('name: ', name); // works
console.log('value: ', event.value); // works
try {
let response = await axios.patch(`/my/path`, {
name: event.value, // need to get the value from name
});
if (response.status === 200) {
//
} else {
console.error('Error: could not update. ', response);
}
} catch (error) {
console.error('Error: sending patch request. ', error);
}
}
我也试过这个开始:
handleChange: async (event, name) => {
...
}
我只是不确定如何在 axios 补丁中使用粗箭头功能。感谢您的任何建议!
最佳答案
不完全清楚,但我猜你想将名称作为对象内部的键传递。如果是这样,请这样做:
let response = await axios.patch(`/my/path`, {
[name]: event.value,
});
关于javascript - 如何将参数向下传递给 await 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58650466/