用的vue3 和element plus,在代码中
const find = async () => {
const res = await axios.put('http://localhost:8080/travel/find/' + id);
categorys.value = res.data.data;
console.log(res.data.data);
const code = res.data.data[0].ydcode;
localStorage.setItem('code', code);
// console.log(categorys.value.id)
// console.log(code.ydcode);
};
find();
console.log(localStorage.getItem('code'));
const code1 = localStorage.getItem('code');
console.log(code1);
const flag = code1 == 1 ? true : false;
console.log(flag);
每次code1获取到的值都是上一次存入的值,网上搜说是因为异步的关系,具体应该怎么修改请大佬指导!