What should be done if vue passes different parameters to get different values?

//api.commonItem 
getCommonItem (value) {
        let variable = ""
        api.commonItem({value: value}).then(res => {
          variable = res.data.name
          console.log("",variable)
        })
        console.log("",variable)
        return variable
      },

clipboard.png

I called the getCommonItem method twice and passed the parameters twice. I wanted to get a different value, but the second time it was empty. Is there something wrong with the logic? please help me to see if the request has not been completed. Variable has been return

.
Mar.16,2021

if you encapsulate commonItem , you should know that a Promise is returned. This is an asynchronous operation. If you want variable to be obtained by getCommonItem callers, either change it to the classic callback :

.
getCommonItem(value) {
    return api.commonItem({value: value}).then(res => {
        let variable = res.data.name
        console.log("",variable)
        return Promise.resolve(variable)
    })
}

getCommonItem(...)
    .then(variable => {
        console.log('', variable)
    })
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e63ac6-45a66.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e63ac6-45a66.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?