我有一個(gè) Vue JS 組件,其中包含一個(gè)模式,詢問(wèn)用戶是否要使用“是/否”選項(xiàng)刪除特定記錄。我希望在單擊“是”按鈕時(shí)觸發(fā) AJAX 刪除請(qǐng)求,現(xiàn)在我嘗試將 ajax 代碼移動(dòng)到我的 Vue 組件中并使用 vue-resource。目前,刪除后我在 chrome devtools 控制臺(tái)中收到以下錯(cuò)誤消息:app.js:38907 刪除http://127.0.0.1:8000/clients/2/delete 419(狀態(tài)未知)127.0.0.1/:1 未捕獲(承諾)響應(yīng) {url: "/clients/2/delete", ok: false, status: 419, statusText: "unknown status", headers: Headers, …}我嘗試過(guò)以下代碼:應(yīng)用程序.js Vue.component('client', require('./components/ClientComponent.vue').default); /** * Next, we will create a fresh Vue application instance and attach it to * the page. Then, you may begin adding components to this application * or customize the JavaScript scaffolding to fit your unique needs. */ import VueResource from 'vue-resource'; Vue.use(VueResource); const app = new Vue({ el: '.table-container', });客戶端組件.vue <template> <li :data-clientID="client.id"><a :href="this.homeRoute">{{ client.first_name + ' ' + client.last_name }}</a> <span class="delete_x" data-toggle="modal" v-bind:data-target="delete_modal" :data-model="client.id">x</span> <div class="modal fade" v-bind:id="delete_id" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="myModalLabel">Are you sure you want to delete client {{ client.first_name + ' ' + client.last_name }}?</h4> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> </div>
1 回答

慕的地6264312
TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊
419 表示 csrf 令牌丟失或不匹配。
可以修改每個(gè)請(qǐng)求默認(rèn)添加x-csrf-token。將此代碼放在使用vueResource之后
Vue.use(VueResource)
Vue.http.interceptors.push(function(request) {
request.headers.set('X-CSRF-TOKEN', $('meta[name="csrf-token"]').attr('content'));
});
https://github.com/pagekit/vue-resource/blob/develop/docs/http.md#request-processing
- 1 回答
- 0 關(guān)注
- 142 瀏覽
添加回答
舉報(bào)
0/150
提交
取消