1.模板
<template>
<view class="flex flex-direction">
<button class="cu-btn bg-red lg" @click="LoginByUUID">一鍵登錄</button>
</view>
</template>
2.方法的實現
<script>
//獲取默認用戶
LoginByUUID() {
var that = this;
var params = {
uuid: "12165486543165455",
nickname: "mjq"
}
this.$api.LoginByUUID(params).then(res => {
console.log(res)
if (res.success && res.code == 200) {
that.userInfo = res.result.userInfo;
console.log(that.userInfo);
uni.setStorageSync("userInfo.uuid",params.uuid)
uni.setStorageSync("userInfo.nickname",params.nickname)
uni.setStorageSync("userInfo",that.userInfo)
}
uni.navigateBack({
delta:3
})
uni.showToast({
title:"登錄成功",
icon:'none'
})
})
}
</script>
3.實現頁面刷新,在onShow中重新獲取一次數據
onShow(options) {
this.getVideos();
this.userInfo = uni.getStorageSync("userInfo");
console.log(this.userInfo)
},
