[Vuejs]-How can I convert my following regular JavaScript code to VueJS?

0👍

You can use Axios:

import axios from 'axios';

const apikey = "?api_key=" + "???";
const region = localStorage.getItem("region").toLowerCase() + "1";
const user = "???";

export function makeRequest()
{
  return axios.get(
    "https://" + 
    region + 
    ".api.riotgames.com/lol/summoner/v4/summoners/by-name/" + 
    user + apikey)
    .then(response =>
    {
      return response.data.name;
    }).catch(error =>
    {
      return null;
    });
}

Perhaps it would be better if you return the Promise received from the Axios rather than the result of it – in this way you can do whatever you want/need with the Promise, e.g. show some notification when there is an error.

Leave a comment