【发布时间】:2017-08-18 19:32:38
【问题描述】:
我需要在使用 ajax axios 的方法中传递参数。
var app = new Vue({
el: '#app',
data: {
urlAdmission:
admissions: [
{ name : 'asdf'},
{ name : 'sd'}
]
},
mounted: function(){
this.allAdmissions()
},
methods: {
allAdmissions: _.debounce( function(){
var app = this
axios.get('http://localhost/school/api/hello')
.then( function(response ){
app.admissions = response.data.admissions
})
.catch( function(error){
console.log(error)
})
})
}
});
正如您在mounted 中看到的,我调用方法this.allAdmissions() 我需要传递一个参数,以便我可以重用该函数。例如 this.allAdmissions('http://localhost/school/api/hello')。然后在 axios.get('url') 中使用它。谢谢
【问题讨论】:
-
您只需要
_.debounce(function(url){}, delay)。 Debounce 将传递参数。 -
我可以这样传递它吗?allAdmission('htpp://localhost/school/api/hello') 然后使用 _.debounce(function(url), 500) 调用它。这是正确的吗?
-
您是想创建一个可重复使用的函数,还是只是确保该函数每半秒执行一次?
-
感谢它的工作!如此简单的解决方案...
-
是的,我认为人们只是有点困惑。