您的位置:首页 > 文旅 > 旅游 > 微信小程序录音和头像上传

微信小程序录音和头像上传

2024/10/6 10:39:41 来源:https://blog.csdn.net/LIGHT03/article/details/139719439  浏览:    关键词:微信小程序录音和头像上传

录音:

WXML

<view class="box4">{{time}}</view>
<button bind:tap="recorderBtn">开始录音</button>
<button bind:tap="removeBtn">结束录音</button>
<button bind:tap="playBtn">播放录音</button>

JS

Page({data:{time:0,clearTime:"",fileText:"",},recorderBtn(){this.data.clearTime = setInterval(()=>{this.data.time += 1;this.setData({time:this.data.time});},1000);a.start()},removeBtn(){clearInterval(this.data.clearTime);this.setData({time:0})a.stop();a.onStop((res)=>{this.data.fileText = res.tempFilePath;})},playBtn(){b.src = this.data.fileText;b.play();},

头像上传:

wxml

<button class="avatar-wrapper" open-type="chooseAvatar" bindchooseavatar="onChooseAvatar"><image class="avatar" src="{{ avatarUrl }}" />
</button>

wxss

.avatar-wrapper {width: 160rpx;height: 160rpx;padding: 0;background: none;
}
.avatar {width: 160rpx;height: 160rpx;border-radius: 20rpx;
}

js

 const defaultAvatar = '../../images/banner.jpg';
Page({data:{avatarUrl:defaultAvatar,}
)},onChooseAvatar(e){console.log(e);const { avatarUrl } = e.detailthis.setData({ avatarUrl })},

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com