求解答,怎么把axios异步请求返回的数据保存下来以便后续使用

求解答,怎么把axios异步请求返回的数据保存下来以便后续使用
async function getInfo() {
  axios.defaults.baseURL = 'https://devapi.qweather.com';
  axios.defaults.timeout = 2000;

  return await axios.get('/v7/weather/3d', {
    params: { location: city, key: apikey },
  });
}

async function RecInfo() {
  try {
    const value = await getInfo();
    return value;
  } catch (error) {
    console.error(error);
    process.exit(-1);
  }
}
console.log(RecInfo());
运行结果及报错内容

img

function getInfo() {
   axios.defaults.baseURL = 'https://devapi.qweather.com';
   axios.defaults.timeout = 2000;
             
    return new Promise(resolve => {
      axios.get('/v7/weather/3d', {
            params: { location: city, key: apikey },
      }).then(res => {
        resolve(res)
      })
    })
}
             
async function RecInfo() {
    try {
        const value = await getInfo();
        return value;
     } catch (error) {
        console.error(error);
        process.exit(-1);
     }
}
console.log(RecInfo())

请求到 在then 方法里 可以用变量保存

storage 持久化存储,vuex 存到内存,通过对应的方法获取

可以考虑把一些会在后续使用的信息存到session里面,比如登录返回的Info