Vue.js客户端Rails API删除对象

时间:2018-11-24 17:24:37

标签: vuejs2 jsonapi-rails

我有一个Rails 5.1 api传递json,Vue.js支持的前端正在使用它。我可以CRU,但不能删除。我已经签入Postman,删除请求按预期工作,但是由于某种原因,它无法通过Vue.js客户端工作。

我怀疑问题出在链接本身,但是我不确定如何通过浏览器发出删除请求,因此我没有在那里进行测试。这是链接的代码:

```

in Entities.vue:

 <tr v-for="entity in entities" :key="entity.id">
      <td>{{ entity.title }}</td>
      <td>{{ entity.description }}</td>
      <td align="center">
        <router-link v-bind:to="{ name: 'EditEntity', params: { id: entity.id } }">Edit</router-link> |
        <a href="#" @click="deleteEntity(entity.id)">Delete</a>
      </td>
    </tr>

```

以及该操作的javascript:

in src/services/EntitiesService.js

deleteEntity (id) {
  return Api().delete('entities/' + id)
}

和src / services / Api.js:

import axios from 'axios'

export default() => {
  return axios.create({
    baseURL: 'http://localhost:3000',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Access-Control-Allow-Origin': '*'
    }
  })
}

这是我可以告诉我的网络请求,看起来不正确:

Request URL: http://localhost:8080/favicon.ico
Request Method: GET
Status Code: 304 Not Modified
Remote Address: 127.0.0.1:8080
Referrer Policy: no-referrer-when-downgrade
Accept-Ranges: bytes
Connection: keep-alive
Date: Sat, 24 Nov 2018 21:57:10 GMT
ETag: W/"144-+Koybw7A2IzbrCsGVT8Z3o3UXFk"
X-Powered-By: Express
Accept: image/webp,image/apng,image/*,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Cookie: ahoy_visitor=7034198d-14a1-4d36-8bcf-495741e6c80a; _ga=GA1.1.491252661.1536002193; _blackops_session=eVpXOUVJNzB1QVI1OE4yVFowWEFDUmRVVXNyTG9FUE9Da2N6RmpsTDVEVmpEOVpDUkUyNTRJeFIwWXB5UU01T2FoYzBBd1NSbnRkdlBOT3BWL1NadG91d0labWcxZmQ3dGIzRkZ6QVlIcURsM0JxS1hERGpndDducnJIMEROYzhGeXlMc2NmSFdVclRrZktqdk02WkU4YmRQdnpvTWlFY3lRQnhBSVJZWTRSOWkybHFtV3JEemtHYTZtZUVrQmVxZkNrc25lK0doQm44VFR4c1RKaHNsUT09LS0zWmZaNWIyZEdDZlRJMWprcmFqNUlBPT0%3D--cd8059919655e6544a22a47b3d93785928644e8c; _book_review_session=Rsqk%2FCrHd8tvmx1vP4l%2B3QltWUP%2BVyE%2BkrPAUWMW%2BbbqOusZORm8vCJ2mlvzTK4aASYVZhSM9bMBGY%2BjDde0WEk7hMryeUagAK0%2FTE%2BlQcsXRVJCVRI39E42Ib4uh%2BXA9bBFk%2B4FeZveolx5njVNedtDgv3C0Y8Lud%2FxkvJYxWl%2FSCkU0eGr1fRheaynCF0fxftsScwQyuTscuhNDoSFC%2BrMgqS0Q%2B1bnl2p--IiFoc%2BJv6jQnURmH--h5yYqRKwplqk%2BY0Eyb7edQ%3D%3D; _jadenseffort_session=4QnEiv%2FhvJQuhUfFF%2BYt5e9tbNnKtzLqkJQ1pGhQ56bbKfkPfY7qP937u2PL0l4T14vfyRNj2m3tP%2FVk1ZQH%2B0yMOV%2Fmbe0KTtvXzCQrqA0PGRqHV9fPwzgZKCpPJit%2FndfXbOMi%2BS6FhSWYKd8%3D--w8URgVaBAILD6N7M--paJNx6RiLH5UN5J0MX7Wng%3D%3D
Host: localhost:8080
If-None-Match: W/"144-+Koybw7A2IzbrCsGVT8Z3o3UXFk"
Referer: http://localhost:8080/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36

0 个答案:

没有答案