vue 获取到后端数据后使用js修改成需要的集合再传给后端

后端的查询和添加编辑接口得到的数据不是同一种格式,所以提交会报错,现在想要把从查询接口得到数据变为添加接口的格式(把数据分为faceUserInfo 和 roleIds)方便提交

添加接口 参数:
image.png

查询接口 参数:

{
  "code": "string",
  "data": {
    "accountStatus": 0,
    "address": "string",
    "birth": "2020-04-20T05:56:33.168Z",
    "companyId": "string",
    "companyName": "string",
    "departmentId": "string",
    "departmentName": "string",
    "email": "string",
    "mobile": "string",
    "phone": "string",
    "positionId": "string",
    "positionName": "string",
    "realName": "string",
    "roleInfos": [
      {
        "actionInfos": [
          {
            "actionKey": "string",
            "actionName": "string",
            "isCategory": 0,
            "parentId": "string"
          }
        ],
        "roleKey": "string",
        "roleName": "string"
      }
    ],
    "userName": "string"
  },
  "mesg": "string",
  "timestamp": "2020-04-20T05:56:33.168Z"
}

这是查询接口的方法;

watch: {
    'visible': {
        handler: function (newVal, oldVal) {
            console.log(newVal)
            if (newVal) {
                console.log(this.userId)
                if (this.userId && this.userId !== '') {
                    getFacUserById(this.userId).then(res => {
                        const _data = res.data
                        // 略
                        this.info = _data
                    })
                } else {
                    this.info = {
                        //略~~~~
                    }
                }
            }
        }
    }
  },
阅读 2.4k
1 个回答
  const facUserInfo = Object.assign({}, this.info);
                    const roleIds = facUserInfo.roleInfos
                    this.info.facUserInfo = facUserInfo
                    this.info.roleIds = roleIds
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题