我正在尝试使用自调用函数来进行 ajax 调用。稍后我想使用响应来填充 Vue 中的数据属性,但由于某种原因我无法做到这一点。
到目前为止,这是我的代码
//chiamata Ajax a servizio
var getData = (function(){
var req = $.ajax({
type:'get',
url:'https://api.myjson.com/bins/a8ohr',
dataType: 'json',
success: function(response)
{
result =JSON.parse(response);
}
});
return {
getResponse:function(){
return req.success;
}
}
}());
var modello = getData.getResponse();
modello
我的目标是在 Vue 中作为数据传递。
这里是 VUE:
var Metromappa = new Vue({
el: '#metromappa',
data: {
modello:modello
},
methods:{
},
beforeMount(){
this.modello = modello;
}
})
我做错了什么?