<script>
export default {
data() {
return {
title: 'hello',
iconList: []
};
},
components: {
HomeHeader,
HomeSwiper,
HomeIcon
},
onLoad() {
this.getHomeInfo()
console.log(this.iconList); // 拿到空数组
console.log(this.title); // 拿到hello
},
methods: {
getHomeInfo () {
uni.request({
url: '../../static/mock/index.json',
success(res) {
const data = res.data.data
console.log(this.iconList); // undefined
this.iconList = data.iconList
// this.title = data.iconList[0].desc
console.log(this.iconList); // 可以拿到返回的数组
console.log(this.title); // undefined 上面没注释的话也可以拿到返回值
//这个里面拿不到data里的值吗
}
})
}
}
};
</script>
![t***@gmail.com](http://img-cdn-tc.dcloud.net.cn/uploads/avatar/000/99/07/12_avatar_mid.jpg?v=0)
t***@gmail.com
- 发布:2019-03-27 15:39
- 更新:2019-03-27 15:43
- 阅读:2599
uni.request 里面拿不到data里的值吗?
分类:uni-app
t***@gmail.com (作者)
谢谢, 确实是这样
2019-03-27 15:48
teller306
回复 t***@gmail.com: onload中怎样拿到数组的值
2020-04-14 17:25