调用方法时将返回数据赋到data变量中
const res = await axios.get('http://localhost:8080/question');
const data = res.data;
通过consle.log(data)发现数据还是空
这可能是
异步数据加载问题:如果使用异步操作(例如Promises或async/await)来获取数据,确保在使用examQuestions
之前数据已经加载完成。异步数据加载可能导致数据在代码执行时还未加载完成,从而出现undefined
的情况。
所以需要将方法通过异步操作
async Qesdata() {
try{
const res = await axios.get('http://localhost:8080/question');
const data = res.data;
this.isShow = false;
this.isShow1 = true;
this.question = data;}
将方法包裹起来
这样数据就可以正常赋值