uni.setStorage函数的学习
部分代码
<script>
var i=0;
export default {
data() {
return{
students:[],
len:'',
}
},
created(){
this.getdata();
this.getphoto();
// this.getphoto();
},
methods: {
getdata(){
//获取该老师的所有学生列表
// return new Promise((resolve, reject) => {
uni.request({
url: 'http://localhost:8081/teacher/loadStudent',
method: 'POST',
data:{
tea_id:2007020301,
},
success: (res) => {
console.log(res.data);
this.students = res.data.data;
this.len=this.students.length;
// console.log("len:",this.len);
console.log("连接成功");
//console.log(this.students[0].stuId);
uni.setStorageSync('学生list',this.students)
// resolve('suc');
this.getphoto();
// this.studyProjects = res.data;
},
// fail:(err)=>{
// reject('err')
// }
})
// })
},
// async getphoto(){
// await this.getdata()
// console.log('我在数据获取之后执行')
// },
//判断并提取当前点击学生信息卡的学生信息,将信息传往更多信息
detailHandler(id){
if(id==this.students[i].stuId){
uni.setStorageSync('students',this.students[i]);
console.log(this.students[i]);
uni.navigateTo({
url:'/pages/teacher/my_student/mystudent_details'
});
return;
}else{
i++;
this.detailHandler(id);
}
},
//获取头像
getphoto(){
console.log("看看?",this.len)
// let len=(uni.getStorageSync(this.students).split()).length
for(var j=0;j<=this.len;j++){
this.students[j].stuPhoto='data:image/png;base64,'+this.students[j].stuPhoto
// console.log("看看呀",this.len)
// uni.request({
// url:'http://localhost:8081/student/findStuPhoto',// 请求地址
// method: 'GET',
// data:{
// stu_id:this.students[j].stuId,
// },
// success: (res) => {
// console.log("hello??");
// console.log("res",res.data.data);
// var photo = res.data.data;
// console.log("stuid"+this.stu_id);
// console.log("photo的值是"+photo);
// this.students[i].stuPhoto='data:image/png;base64,'+ photo;
// },
// fail: (err) => {
// console.log("hello??")
// }
// });
}
}
}
}
</script>
主要代码
created(){
this.getdata()
},
methods: {
getdata(){
try {
this.students[0] = uni.getStorageSync('students');
console.log("1231212"+this.students.stuId);
console.log("取缓存成功");
} catch (e) {
console.log("取缓存失败")
}
},