第一种写法:

  getData() {
    fetch('/api/list_all').then(res => {
      return res.json()
    })
    .then(res => {
      if(res.code === 200) {

      }
    })
    .catch(err => {
      console.log(err)
    })
  }

第二种写法:

  async getData() {
    try {
      const result = await fetch('/api/list_all')
      const res = await result.json()
      if (res.code === 200) {

      }
    } catch (error) {
      console.log(error)
    }
  }

 

相关文章:

  • 2022-12-23
  • 2021-10-16
  • 2021-04-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
猜你喜欢
  • 2022-12-23
  • 2021-07-08
  • 2021-11-24
  • 2022-12-23
相关资源
相似解决方案