ajax – 如何从这里返回数据.$http.get在vue js中
发布时间:2020-12-16 02:45:54 所属栏目:百科 来源:网络整理
导读:嗨我在使用laravel 5中的vue js在我的ajax调用中返回数据时遇到问题.我有一个状态数组并在循环内调用ajax的函数.现在的问题是,似乎ajax无法返回值.这是我的代码: ready: function() { var dData = {}; for (var i=0; ithis.pState.selectedState.length; i+
嗨我在使用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 } 任何想法的家伙? 解决方法
如果您只想将返回的结果分配给变量,请尝试以下操作:
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 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |