你好 #Vue.js2我在創建一個在表單提交事件中呼叫的函式時遇到問題 這個函式需要2個引數:事件和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 截圖
uj5u.com熱心網友回復:
原始事件$event在處理程式內部可用v-on:。
檔案:行內處理程式中的方法
有時我們還需要訪問行內陳述句處理程式中的原始 DOM 事件。
$event您可以使用特殊變數將其傳遞給方法
所以這應該作業:
<form @submit.prevent="updatePost($event, post.id)">
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/447183.html
標籤:javascript 形式 Vue.js 多部分数据
下一篇:從一個陣列中獲取所有資料
