你好 #Vue.js2 我在创建在表单提交事件中调用的函数时遇到问题 此函数需要采用 2 个参数:EVENT 和 ID 我现在的问题是,当我调用这个函数时,我无法在没有错误的情况下指定事件参数,因此我的表单数据和我的 id 将在我的日志中未定义。 有没有更好的方法来处理我的表单?
updatePost(event, id) {
const postId = id;
const updatedPost = new FormData(event.target); // Any way to not use event param to save this ?
console.log(updatedPost, postId);
},
// Call in my Template but :
<form @submit.prevent="updatePost(post.id)">
ps :由 2 个输入类型文本和 1 个输入类型文件组成的表单。 Vue.js screenShot
最佳答案
原始事件在 v-on:
处理程序中作为 $event
提供。
Sometimes we also need to access the original DOM event in an inline statement handler. You can pass it into a method using the special
$event
variable
所以这应该有效:
<form @submit.prevent="updatePost($event, post.id)">
关于javascript - Vue.js : form-data Event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71560299/