栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

美食杰-编辑个人资料

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

美食杰-编辑个人资料

页面展示

二、过程

1.进行页面渲染 这里用到了element组件库 修改名称和个人简介直接用v-model双向数据绑定就可以

 div class edit 
 div class edit-item 
 span class label 修改头像 /span 
 upload-img
 imgMaxWidth 210 
 action /api/upload?type user 
 :imageUrl avatar 
 res-url (data) {avatar data.resImgUrl} 
 /upload-img 
 /div 
 div class edit-item 
 span class label 修改名称 /span 
 div 
 el-input v-model name class create-input placeholder 请输入内容 /el-input 
 /div 
 /div 
 div class edit-item 
 span class label 个人简介 /span 
 div 
 el-input v-model sign type textarea class create-input placeholder 请输入内容 /el-input 
 /div 
 /div 
 div 
 el-button 
 class send 
 type primary 
 size medium 
 click save 
 保存 /el-button 
 /div 
 /div 

因为上传图片 在别的地方也会用到 所以创建了一个单独的组件upload-img 这里使用的是element组件

 el-upload
 class avatar-uploader 
 :action action 
 :show-file-list false 
 :on-success handleAvatarSuccess 
 :before-upload beforeAvatarUpload 
 img v-if imageUrl :src imageUrl class avatar 
 i v-else class el-icon-plus avatar-uploader-icon /i 
 /el-upload 

通过props获取父组件传递的参数 这里用的是对象

props:{
 action:String,
 maxSize:{
 type:Number,
 default:2
 imageUrl:{
 type:String,
 default: 
 imgMaxWidth:{
 type:[Number,String],
 default: auto 
 },

图片上传在upload-img组件里触发handleAvatarSuccess 图片上传之后 和beforeAvatarUpload 图片上传 两个element的参数 来进行判断是否符合条件 上传之后调用父组件edit的‘gai’方法 让图片显示

// 图片上传之后
 handleAvatarSuccess(res, file) {
 console.log(res,file);
 if(res.code 1){
 this.$message({
 message:res.mes,
 type: warning 
 return
 this.$emit( gai ,URL.createObjectURL(file.raw))
 console.log(this.imageUrl);
 this.$emit( res-url ,{
 resImgUrl:res.data.url
 // 图片上传之前
 beforeAvatarUpload(file) {
 限制图片类型
 const isJPG file.type image/jpeg 
 // 限制图的内存大小
 const isLt2M file.size / 1024 / 1024 
 if (!isJPG) {
 this.$message.error( 上传头像图片只能是 JPG 格式! 
 if (!isLt2M) {
 this.$message.error( 上传头像图片大小不能超过 2MB! 
 console.log(file);
 return isJPG isLt2M;
 }

总结

到这里编辑个人资料就结束了 谢谢观看

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/267879.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号