use*_*670 4 ajax vue.js laravel-5
嗨,我在 Laravel 5 中使用 vue js 在我的 ajax 调用中返回数据时遇到问题。我有一个状态数组并在循环内调用 ajax 的函数。现在的问题是 ajax 似乎无法返回值。这是我的代码:
ready: function() {
var dData = {};
for (var i=0; i<this.pState.selectedState.length; i++){
dData = this.displayCounty(this.pState.selectedState[i])
}
console.log(dData);
},
methods:{
displayCounty: function(val){
var nData = {};
// ajax get County list
this.$http.get('/api/counties/' + val )
.success(function(counties){
return counties;
})
.error(function(){
}) //ajaxcall
}// displaCounty
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
小智 5
如果您只想将返回的结果分配给变量,请尝试以下操作:
ready: function() {
this.getCounties;
},
data: {
counties: []
},
methods:{
getCounties: function(val){
// ajax get County list
this.$http.get('/api/counties/' + val )
.success(function(counties){
this.counties = counties;
})
.error(function(){
}); //ajaxcall
} // displayCounty
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11834 次 |
| 最近记录: |