【问题标题】:Problem put axios update user Strapi and NuxtJS问题把 axios 更新用户 Strapi 和 NuxtJS
【发布时间】:2020-03-05 15:45:53
【问题描述】:

strapi 中的权限有问题。

我创建具有身份验证角色的用户并尝试使用 axios 修改数据。

但不可能已经修改,因为返回被禁止。我看看用户是否有权限,更新是签入角色身份验证。

如果我在角色 public 中检查更新,我用 axios 进行的修改是可以的。为什么 ?我不明白这个问题。

我的发送代码

       .put(
         `https://localhost:4000/users/${this.data.id}`,
         {
           headers: {
             Authorization: `Bearer ${token}`
           },
           Nom: 'JEAN'
         }
       )
       .then((res) => {
         // Handle success.
         console.log(res)
       })
       .catch((error) => {
         // Handle error.
         console.error('An error occurred:', error)
       })```

Thank you

【问题讨论】:

    标签: vue.js nuxt.js strapi


    【解决方案1】:

    我不确定 axios 请求的格式是否正确。

    根据本文档 - https://github.com/axios/axios#axiosconfig

    这可能应该是这样的:

    axios({
      method: 'put',
      url: `https://localhost:4000/users/${this.data.id}`,
      data: {
        username: 'JEAN'
      },
      headers: {
        Authorization: `Bearer ${token}`
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      相关资源
      最近更新 更多