把要用的方法写到methods里面就行了,最后在调用就行了
methods: {
requestceshi: async function(userId){var aa = "";
var [error, res] = await uni.request({
url: this.$Url + "Userinfo/findById",
dataType: "json",
method: "GET",
data: {
id: userId
}
});
console.log(res.data);
this.userName = res.data.data.userName;
console.log(res.data.data.userName );
}
}
官网的帮助文档:https://uniapp.dcloud.io/api/README?id=promise-%e5%b0%81%e8%a3%85
不过写的和我写的有点不一样