如何在vue js中向数据库发送bolean值

tgabmvqs  于 2023-03-19  发布在  Vue.js
关注(0)|答案(1)|浏览(133)

这就是我派 Postman 来的方式

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

这是我如何发送vue

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”:真的,

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

由于isAdmin = true无法通过,我不断地被取消授权

h6my8fg2

h6my8fg21#

用这个

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

而不是数据。附加

相关问题