vue的学习

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("取缓存失败")					
				}

			},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值