简体   繁体   中英

How can I access a variable outside function?

How can I access to a variable outside function next.js i want to get name outside the data

let getDetail = async () => {
    let body = { 
      code: '12',
      provider: 'bb', 
      
    };
     let { data } = await Axios.post(
      "https://blbla",
      JSON.stringify(body)
    );   
      let { name } = data;
      
  };

You could return name,

let { name } = data;
return name;

and then when you call the function, if you need the name, you could say:

name = getDetail();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM