[Vuejs]-Convert fetch to axios

0πŸ‘

const image = async (url) =>
    await axios.get(url)
    .then(response => {
      // can access blog directly from response... 
    }
    

Read more about axios here

-2πŸ‘

Here: I am assuming this is a get request?

    const image = async (url) => {
    
   return await axios.get(url)
      .then((response) => {
          return response.blob();
      })
      .then(
        (blob) =>
          new Promise((resolve, reject) => {
            const reader = new FileReader();
            reader.onloadend = () => resolve(reader.result);
            reader.onerror = reject;
            reader.readAsDataURL(blob);
          })
      );
    }

Leave a comment