我开始使用 Laravel 和 Nuxt Js 创建一个新应用程序。 我有两个VPS 服务器:
- 第一个包含我的Nuxt JS(前端)
- 第二个是基于Laravel的终点点(后端)
我已经创建了很多页面,我将数据正确插入到我的数据库中。现在我尝试创建一个新函数来更新用户数据,但在提交表单后出现错误,因为我使用相同的 axios 代码插入。
现在我正在没有 token 的情况下工作,并且我知道它的不安全方式。 我想知道如何在 Nuxt JS 前端 Laravel 后端之间传递 token 。 我有两台服务器。
我得到的错误是:
CSRF token mismatch.", exception: "Symfony\Component\HttpKernel\Exception\HttpException
这是我的 Axios 代码:
edit (customerId, submit = false) {
this.editMode = true
this.customerId = customerId
if (submit === 1) {
const formData = $('#add-customer').serialize()
this.$axios.$post('/customer/update', formData).then((response) => {
this.refresh = true
})
} else {
this.$axios.$get('/customer/edit?customer=' + customerId).then((response) => {
this.formFields = response.data[0]
})
}
}
当我将这一行从 post 更改为 get 时,它工作正常
this.$axios.$post('/customer/update', formData)
最佳答案
我建议使用单个 Redis 服务器进行 session 管理,这样您就有一个集中的位置。或使用数据库,有关更多详细信息,请查看 laravel 文档
关于javascript - 我如何在我的 nuxt vps 上使用 laravel csrf token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59533255/