是this指向问题,如果success写成普通函数的形式,那么this指向success自身,应该指向对象自身的
uni.request({
url:‘http://localhost:3000/api/search,
method:‘get’,
success(res) {
this.bookDetail = res.data
}
})
解决:
1.写成箭头函数形式
uni.request({
url:‘http://localhost:3000/api/search,
method:‘get’,
success:(res) => {
this.bookDetail = res.data
}
})
2.添加var that=this
getdata(){
var that=this;
uni.request({
url:‘http://localhost:3000/api/search,
method:‘get’,
success(res){
that.bookDetail = res.data
}
})
}
标签:uniapp,success,渲染,res,get,api,3000,method,页面
From: https://www.cnblogs.com/ljh980217/p/16664362.html