Component组件怎么赋值data?
我现在有这么一个功能,卡着了,各位大神帮忙看一下:
var index = [0,0,0]
var AreaJson = [];
var provinces = [];
var citys = [];
var areas = [];
var http = require('../../utils/request.js');
http.post('/food/type/address/list', {
data:{},
}).then(res => {
debugger
var that = this;
AreaJson = res
var provincese = [];
for (var i = 0; i < AreaJson.length;i++){
provincese.push(AreaJson[i].name);
}
provinces = provincese //我要将provincese 赋值给data的中的provinces
console.log(provinces)
var citysd = [];
for (var i = 0; i < AreaJson[0].city.length;i++){
citysd.push(AreaJson[0].city[i].name);
}
citys = citysd
var areasd = [];
areasd = AreaJson[0].city[1].area;
areas = areasd
}).catch(err => {
console.log(err)
})
Component({
properties: {
},
data: {
provinces: provinces, //这个值就是上面Component外调用后台接口返回的值
citys: citys,
areas: areas,
value:[0,0,0],
province: '北京市',
city: '北京市',
area: '东城区'
},
/**
* 组件的方法列表
*/
methods: {
},
})
我要将上面http.post,后台返回的数据赋值给data中provinces 和 citys 和 areas,但是不知道这个Component怎么初始化的,将调用后台的post写到Component里面任何地方都不行,只能写到外面才会执行。但是写到外面,后台获取结果之后,结果怎么赋值给给data参数。用this.setData也不管用。
大佬有啥办法