ReadData(context){
      // 第一个promise开始
      var promise1 = new Promise((resolve,reject)=>{
        axios.get("http://localhost:8080/api/fenlei.json").then((response)=>{
          // console.log(response.data)
          resolve(response.data)
        }).catch((error)=>{
          reject(error)
          console.log(error)
        })
      }).then((data)=>{
        context.commit("readJson",data)
      }).catch((error)=>{
        console.log(error)
      })
      // 第一个promise结束
      // 第二个promise开始
      var promise2 = new Promise((resolve,reject)=>{
        axios.get("http://localhost:8080/api/list.json").then((response)=>{
          resolve(response.data)
        }).catch((error)=>{
          console.log(error)
          reject(error)
        })
      }).then((data)=>{
        context.commit("ReadlistJson",data)
      }).catch((error)=>{
        console.log(error)
      })
      //第二个结束

     //全部完成以后,统一进行操作,为了防止多个请求有没有完成的,影响下一步操作。
      Promise.all([promise1,promise2]).then(()=>{
        context.commit("SortItems")
      }).catch((error)=>{
        console.log(error)
      })
    }

  

相关文章:

  • 2021-09-10
  • 2022-01-08
  • 2021-04-20
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-10-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
相关资源
相似解决方案