这就是我派postman 的方式,它是有效的

{
    "isAdmin": true,
    "type": "shoes",
    "description": "true"
}

我就是这样送过go 的

 async onAddCategory() {
     
      let data = new FormData();
      data.append("type", this.type);
    data.append("isAdmin", this.isAdmin);
      data.append("description", this.description);
      const response = await axios
        .post("http://localhost:4000/api/categories", data, 
        })
        .then(response => {
          console.log(response);
        })
        .catch(err => {
          console.log(err);
        });
    },

这是我的控制台,显示"isAdmin":True,

{
    "_id": "640f4e785d1e1c8d7c1be439",
    "isAdmin": true,
    "name": "t",
    "email": "t@gmail.com",
    "password": "$2a$10$O1hMb2Tc7mdK7iD4gbZ/VeV1htualyj0Fry86pt6stv7boIk.0ft2",
    "__v": 0
}

我一直处于未授权状态,因为isAdmin=True无法通过

推荐答案

用这个

   var data = {
        isAdmin: this.isAdmin,
        description: this.description,
        type: this.type
      };

而不是data.append

Vue.js相关问答推荐

使用V-TOOLTIP(实例化)使工具提示在V-文本字段中显示清晰的图标

Vuejs 通过数据键迭代复杂对象

Vue3如何将自定义事件绑定到路由视图中的特定组件?

两个div元素之间的vue2过渡

如何在 vue 路由中导航到 Bootstrap-vue 选项卡中的特定选项卡?

VueJS:如何在组件数据属性中引用 this.$store

Vue 和 Bootstrap Vue - 动态使用插槽

如何为 Vue 项目设置 lint-staged?

Vuejs在复选框 Select 上切换div可见性

命名空间模块身份验证的重复命名空间身份验证

带有子菜单的 Vuetify 导航抽屉

Nuxt 应用程序在刷新动态路由时返回 404(Tomcat 服务器)

Vue代理设置不起作用

Vue Cli 3 不允许我在 Webpack 中处理 SVG

如何告诉 Vue-cli 我的应用程序的入口点在哪里?

根据路由动态插入 CSS 类到导航栏

重新加载页面正在 vue 组件中的插槽上闪烁内容

将 SignalR 与 Vue.js 和 Vuex 集成

脚本npm run dev和npm run watch是做什么用的?

为什么 router.currentRoute.path 没有react?