【小程序】微信小程序获取头像、呢称2013年最新解决方案(已解决)

一、效果

 二、wxml代码

<!-- 点击头像获取头像 -->
<view style="margin-bottom: 20px;text-align: center;">---- 点击头像获取logo ----</view>
<view class="logo">
    <button style="width: 100px;height:100px;" class="Logobutton" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
        <image class="logoImage" src="{{avatarUrl}}"></image>
    </button>
</view>

<view style="margin-top: 20px;margin-bottom: 20px;text-align: center;">---- 点击按钮获取logo ----</view>
<view class="logo">
    <button class="Logobutton_2" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
        点击获取头像
    </button>
</view>
<view style="margin-top: 20px;margin-bottom: 20px;text-align: center;">---- 获取logo临时图片地址 ----</view>
<view style="width:100%;height:80px;background-color: rgb(233, 233, 233);">
    地址:{{avatarUrl}}
</view>
<!-- 点击获取昵称 -->
<view style="margin-top: 20px;margin-bottom: 20px;text-align: center;">---- 点击获取昵称 ----</view>

<view style="text-align: center;">
    <input type="nickname" class="weui-input" placeholder="点击选择昵称" />
</view>

<!-- <view>
    <button class="Logobutton" type="nickname">
        获取昵称
    </button>
</view>  -->

三、wxss代码

/* pages/car/car.wxss */
.logo {
    /* background-color: rgb(250, 217, 217); */
}

.Logobutton {    
    border-radius: 10px;
    width: 100px;
    height:100px;
    padding: 0;
}
.logoImage {
    height:100%;
    width: 100%;
}
.Logobutton_2 {    
    border-radius: 5px;
    width: 1000px;
    height: 50px;
    background-color: green;
    color:white;
    line-height: 50px;
    padding: 0;
}

.weui-input{
    width: 90%;
      height: 60px;
      margin:20px auto;
      background: rgb(236, 236, 236);
      border-radius: 5px;
      padding-left: 15px;
      /* color:red; */
}


四、js代码

const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
    data: {
        avatarUrl: defaultAvatarUrl,
    },
    onChooseAvatar(e) {
        const {
            avatarUrl
        } = e.detail
        this.setData({
            avatarUrl,
        })
        console.log(avatarUrl);


    }
})

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

敦厚的曹操

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值