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

录音:

WXML

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

JS

javascript 复制代码
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

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

wxss

css 复制代码
.avatar-wrapper {
  width: 160rpx;
  height: 160rpx;
  padding: 0;
  background: none;
}
.avatar {
  width: 160rpx;
  height: 160rpx;
  border-radius: 20rpx;
}

js

javascript 复制代码
 const defaultAvatar = '../../images/banner.jpg';
Page({
  data:{
    avatarUrl:defaultAvatar,}
)},

onChooseAvatar(e){
    console.log(e);
    const { avatarUrl } = e.detail
    this.setData({ avatarUrl })
  },
相关推荐
正小安4 小时前
如何在微信小程序中实现分包加载和预下载
前端·微信小程序·小程序
说私域4 小时前
基于定制开发与2+1链动模式的商城小程序搭建策略
大数据·小程序
丁总学Java10 小时前
微信小程序-npm支持-如何使用npm包
前端·微信小程序·npm·node.js
工业互联网专业11 小时前
毕业设计选题:基于ssm+vue+uniapp的校园水电费管理小程序
vue.js·小程序·uni-app·毕业设计·ssm·源码·课程设计
说私域15 小时前
社群团购中的用户黏性价值:以开源小程序多商户AI智能名片商城源码为例
人工智能·小程序
迷雾yx19 小时前
开发微信小程序 基础02
微信小程序·小程序
迷雾yx19 小时前
开发微信小程序 基础03
微信小程序·小程序
说私域19 小时前
地理定位营销与开源AI智能名片O2O商城小程序的融合与发展
人工智能·小程序
小雨cc5566ru1 天前
uniapp+Android面向网络学习的时间管理工具软件 微信小程序
android·微信小程序·uni-app
小雨cc5566ru2 天前
hbuilderx+uniapp+Android健身房管理系统 微信小程序z488g
android·微信小程序·uni-app