vue调用接口出现$ref问题

请求一个接口,但是这个接口里面有$ref的字段,内容无法正常显示

图片描述这是请求到的数据..

后端说是要把这个字段的值替换成state.downloadCategoryMap重新请求一下就变正常了

大家有遇到这种情况的吗?

这是后端给出的处理办法 ↓↓↓

let diguiReflectList = (theObj) => {
        if (theObj) {
          if (theObj.children) {
            theObj.children = theObj.children.map(item => diguiReflectList(item));
          }
          if (theObj["$ref"]) {
            return eval(theObj["$ref"]
              .replace("\$.data.downloadCategory", "state.downloadCategoryMap")
              .replace("\$.data", "state.downloadCategoryMap"));//千万注意二级路径的问题
          } else {
            theObj.title = theObj.id;
            theObj.expand = true;
            state.downloadCategoryMap[theObj.id] = theObj;
            return theObj;
          }
        } else {
          return theObj;
        }
      };
阅读 3.5k
3 个回答

可能是后端接口没有写好,也有可能是后端有意为之。从你给出的代码看,更像是后者。

后端返回的为啥会是这种数据,不应该是纯文本的json字符串吗

这种瞎几把给字段的后台,给我看到就是一顿骂

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题