Misunderstanding caused by a simple shallow copy of the then callback assignment to the returned data in axios

1. Data manipulation in advance:

Interface postman test result:
Insert picture description here
code snippet:

// 获取事件分类
interactions.getThingsclass = async function () {
    
    
  let refreshToken = localStorage.getItem("token");
  axios
    .get("http://202.101.162.69:8089/proxy/top/api/class/condition", {
    
    
      headers: {
    
    
        Authorization: refreshToken,
      },
    })
    .then((res) => {
    
    
      console.log("total事件分类",res)
      console.log("23行打印流转状态",components.thingsClass.sbztList);
      components.thingsClass.jsdwList = res.data.data.jsdwList;
      components.thingsClass.sbztList = res.data.data.sbztList;
      console.log("26行打印流转状态",components.thingsClass.sbztList);
      components.thingsClass.sfcqList = res.data.data.sfcqList;
      components.thingsClass.sjflList = res.data.data.sjflList;
      components.thingsClass.jsdwList.unshift({
    
     name: "全部" });
      components.thingsClass.sbztList.unshift({
    
     name: "全部" });
      components.thingsClass.sfcqList.unshift({
    
     name: "全部" });
      components.thingsClass.sjflList.forEach((item)=>{
    
    
        item.subset.forEach((item_i)=>{
    
    
          if(item_i.name != "其他" && item_i.name != "金融监管" && item_i.name != "农林水利"&& item_i.name != "质量监管" && 
          item_i.name != "文教体育" && item_i.name != "老龄殡葬" && item_i.name != "困难救助"&& item_i.name != "优抚安置"&& item_i.name != "工商监管") {
    
    
            components.chilrenmenu.push({
    
    name:item_i.name,id:item_i.id})
          }
          
        })
      })
      components.chilrenmenu.unshift({
    
    name:"全部"});
      console.log("42行打印流转状态",components.thingsClass.sbztList);
    });
};
可以看到是赋值在前,在数组前面第一项追加"全部”在后,此时进行一个打印操作:

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43131046/article/details/113729724