methods: {
initData(id) {
console.log(id);
const that = this
console.log('cakeid' + id);
uni.request({
url: config.apiURL + '/cake/' + id,
method: 'GET',
success: function(res) {
console.log(this);
// that.$set('cake',res.data.data)
that.cake = res.data.data;
console.log(this.cake)
}
});
}
},
onLoad 的 this 不是指向 vm的,打印是 undefined,试了 很久,还是用回了 mounted函数
mounted() {
console.log(this.$route)
this.initData(this.$route.query.cakeId)
},
uni.request 的 success 的回调函数的 this 也不是指向 vm的,还要用一个 that 的变量提前引用来调用