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

录音:

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 })
  },
相关推荐
2601_963869954 小时前
力序健身房管理系统
微信小程序·小程序
一 乐7 小时前
二手交易平台|基于springboot + vue二手交易平台(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序
拖孩12 小时前
给小程序加「一键发公众号贴图」,我把 wx.shareToOfficialAccount 的三个坑趟了一遍
前端·后端·微信小程序
微擎应用市场12 小时前
鲸飞云 PMS 系统 —— 现代化酒店运营的智能管理解决方案
小程序
疯狂小猫咪16 小时前
教务管理系统课时消课模块设计思路
大数据·小程序
meiying883817 小时前
微信商城小程序怎么开发?2026 从店铺架构到下单链路的技术选型拆解
小程序
扶风ff1 天前
练题簿小程序:家庭在线练题,课后复习更简单
学习·小程序
高级程序源2 天前
django招聘网站信息爬取与分析系统79704-计算机课程设计、毕业设计
后端·python·mysql·小程序·django·flask·课程设计
StevenLdh2 天前
第四期 · 云端同步与冲突仲裁:离线可写、多端一致的工程解法
java·微信小程序
m0_462803882 天前
会议签到如何设置手写签名?从创建签到到导出签名 PDF 的完整流程
微信小程序