我是(Axios,PHP和vue.js)的新手,我想在表单的编辑表单中填充当前数据,而无需使用for循环
当我使用下面的代码时,它确实将数据提交到我在输入字段中键入的SQL数据库
updateRecord: function (id) {
let formData = new FormData();
console.log(formData);
formData.append('name', this.name);
formData.append('msisdn', this.msisdn);
const blackList = {};
formData.forEach(function(value, key){
blackList[key] = value;
});
axios({
url: 'http://whizzdev/blackListEdit.php?id=' + id + "&action=update",
method: 'post',
data: formData,
config: {headers: {'Content-Type': 'multipart/form-data'}}
});
<div class="modal-container">
<form>
<label>Name</label>
<select v-model="name" type="select">
<option>Prevent MSISDNS from PLAYING</option>
<option>Prevent MSISDNS from WINNING</option>
</select>
<label>Msisdn</label>
<input type="text" v-model="msisdn">
</form>
<button type="submit" value="update" @click="updateRecord(blackList.id)">Save</button>
<button type="reset" @click="showModal = false">back</button>
</div>
</div>
答案 0 :(得分:0)
您的代码也可以在没有以下代码的情况下工作,因为blacklist
中未使用updateRecord()
:
const blackList = {};
formData.forEach(function(value, key){
blackList[key] = value;
});