鍍金池/ 問答/HTML/ vue調(diào)用接口出現(xiàn)$ref問題

vue調(diào)用接口出現(xiàn)$ref問題

請求一個接口,但是這個接口里面有$ref的字段,內(nèi)容無法正常顯示

圖片描述這是請求到的數(shù)據(jù)..

后端說是要把這個字段的值替換成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;
        }
      };
回答
編輯回答
解夏

可能是后端接口沒有寫好,也有可能是后端有意為之。從你給出的代碼看,更像是后者。

2017年8月4日 22:18
編輯回答
夏木

后端返回的為啥會是這種數(shù)據(jù),不應(yīng)該是純文本的json字符串嗎

2017年8月17日 00:02
編輯回答
氕氘氚

這種瞎幾把給字段的后臺,給我看到就是一頓罵

2017年9月11日 05:42