赞
踩
今天刚刚接触到如何调取接口,就记录一下。
如果有人和我一样,只是需要在页面内调取后端接口,把数据渲染到页面上,就可以向我这样,里面很多的东西都是固定的。
当我们需要渲染页面时,常常很多页面的数据是从上个页面拿到的,所以我们需要一个**onLoad()**函数,在加载时候获取数据。具体如下:
data(){
return{
friendslist:[],
prams:{
id:""
}
}
},
onLoad(option) {
const item = JSON.parse(decodeURIComponent(option.item));
console.log(item,'*****')//这里为什么要打印,看看传过来的数据是怎么样的
this.prams.id=item.id
this.userInfo()
},
methods:{
userInfo() {
let data=this.prams
this.$request.get('/api/new/patient/detail',data,res=>{
let data=res.data
console.log(data.friend_relation,"数据")
if(res.code="200"){
this.friendslist = data.friend_relation
}
})
},}
格式差不多是这样,把里面的内容换了即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。