我是vue js的新手,我发现有些地方有点混乱,但这里是我面临的最新困惑。
DELETE http://simvuecore/api/contoh/0 404 (Not Found)
这意味着axios发送
position
当控制器期望
id
尽管
作为参考,以下是我的代码:
API routes
:
Route::delete('/contoh/{contoh}', 'contohController@destroy');
contohController
public function destroy(contoh $contoh)
{
$contoh->delete();
return response('terhapus', 200);
}
store.js
:
state: {
contoh: []
},
mutations: {
deleteContoh(state, id) {
const index = state.contoh.findIndex(item => item.id == id)
state.contoh.splice(index, 1)
}
},
actions: {
deleteContoh(context, id) {
axios.delete('api/contoh/' + id)
.then(response => {
context.commit('deleteContoh', id)
})
},
}
contohItem.vue
:
methods: {
removeContoh(id) {
this.$store.dispatch('deleteContoh', id)
},
POSTMAN
当vue要求时,
delete
是唯一一个因为这个不起作用的
位置
和
身份证件
问题:
如何告诉axios发送
身份证件
而不是
更新:
我把这个放进去了
继续项目.vue
:
<span @click="removeContoh(index)" class="remove-contoh">X</span>
在我把它改成这样之后它就起作用了:
<span @click="removeContoh(id)" class="remove-contoh">X</span>