RE: RE: Nuxt开发指南
You are viewing a single comment's thread from:

RE: Nuxt开发指南

Words
61
Reading
1 min
Listen
Play
7M

$fetch是与useFetch类似的封装函数,不过$fetch使用却是大大不同。
useFetch会和表格关联,造成一些不必要的http访问,$fetch则不会。
$fetch不能直接捕获到错误,只能通过 try catch

const baseURL = "http://localhost:6200"  
const option = {
  method: "POST",
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL
}
const loginApi2 = async (url, body) => {
  let obj = {
      ...option,
      body
  }
  let res
  try {
    res = await $fetch(url, obj)
    console.log(566, "login api2", res)
  } catch (error) {
    res = error
    console.log(444, "login api2 error", error)
  }
  return res
}
@lemooljiang: | Ecency