【发布时间】:2018-08-08 06:51:39
【问题描述】:
我正在尝试构建一个简单的测验应用程序。它有一些在数据库中的问题。我正在使用 AXIOS 请求获取那些。 我正在做这样的事情:
var app = new Vue({
el:"#app",
data:{
currentQuestion:0,
question:{}
},
methods:{
next:function(){
this.currentQuestion+=1;
this.loadQuest();
} ,
loadQuest:function(){
axios.get('/questions').then((response)=>{
//console.log(response.data[this.currentQuestion]);
this.question = response.data[this.currentQuestion];
})
}
},
mounted(){
this.loadQuest();
},
});
在这里,您可以看到每当我单击下一个问题按钮时,都会调用 loadQuest() 并向服务器发送请求。有没有什么办法不在每次点击下一个按钮时发送请求,而只是增加 currentQuestion 变量并加载下一个问题?
【问题讨论】:
标签: javascript php vue.js vuejs2 vue-component