我正在使用ajax发布请求将数据从表单发送到数据库。请求成功后,将数据推送到存储中的阵列。为了不再次从后端API加载全部。工作正常。
但是,在将数据推送到数组后,我需要清除表格,以便用户添加其他数据。并且在将其推送到数组之前先清除表单。
typedef struct Move replay_move(int sequence_number)
{
char player;
int X[sequence_number];
int Y[sequence_number];
}ReplayX, ReplayO;
while (answer != n)
{
ReplayX.player = 'X';
ReplayO.player = 'O';
grid[gridsize][gridsize] = make_move(ReplayX.X[sequence_number], ReplayX.Y[sequence_number], ReplayX.player);
printf("Next or Exit (n,e)?");
scanf("%c",&answer);
gameProgress = player_won (ReplayX.player);
sequence_number++;
grid[gridsize][gridsize] = make_move(ReplayO.X[sequence_number], ReplayO.Y[sequence_number], ReplayO.player);
printf("Next or Exit (n,e)?");
scanf("%c",&answer);
sequence_number++;
gameProgress = player_won (ReplayO.player);
}
}
和store.js
<template>
<div class="addToDB">
<form @submit.prevent="add">
<label> Name </label>
<input type="text" v-model="form.name"/> <br/>
<label> Price </label>
<input type="number" v-model="form.price"/> <br/>
<button>Add</button>
</form>
</div></template>
答案 0 :(得分:0)
这应该对您有用。
// Your current code (not working)...
/*
axios.post('http://test.com', this.$data.form, {
headers: {
"Authorization": `Bearer ${this.$store.getters.currentUser.token}`
}
})
.then((response) => {
this.$store.commit('addList', this.form);
})
.finally(() => this.clearForm())
*/
// Updated code...
axios.post('http://test.com', this.$data.form, { headers: { 'Authorization': `Bearer ${this.$store.getters.currentUser.token}` } })
.then((response) => {
this.$store.commit('addList', this.form);
return Promise.resolve();
})
.then(() => this.clearForm());