微信小程序更换头像的实现源码

微信小程序更换头像的实现源码

html

  <view class='top_head_border'>   
 <image class='top_head' src='{{head}}'></image>  
 <view class='top_text'  mode="aspecFill" bindtap="headimage">点击更换头像</view>
 </view>

css

.top_head {
  margin-top: 30rpx;
  width: 160rpx; 
  height: 160rpx; 
  border-radius: 100%; 
  border: 1px solid rgba(51, 51, 51, 1);
       }
.top_text { 
 line-height: 40rpx;  
 color: rgba(229, 28, 35, 1);  
 font-size: 28rpx;  
 font-family: Roboto;
 }
  data: {  
     // 切换头像  
    showModal: false,   
     head: "/img/1.png",   
     },
       // 点击换手机相册或者电脑本地图片    
       headimage: function() {   
          var _this = this;  
           wx.chooseImage({    
               count: 1, // 默认9      
                sizeType: ['original', 'compressed'],       
                  // 指定是原图还是压缩图,默认两个都有      
                   sourceType: ['album', 'camera'],      
                  // 指定来源是相册还是相机,默认两个都有    
                   success: function(res) {       
                   // 返回选定照片的本地文件路径tempFilePath可以作为img标签的src属性显示图片 
                   //然后请求接口把图片传给后端存到服务器即可       
                     _this.setData({    
                       head: res.tempFilePaths      
                                          }) 
                                }    
                   }) 
      },
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值