收藏
回答

微信小程序调用 wx.chooseImage 后导致 input 展示异常?

微信小程序调用 wx.chooseImage 后导致 input 展示异常,看起来像是被清空了。

API:chooseImage

影响组件: input

机型:iPhone12 IOS 15.4.1

基础库:2.25.0

现象:

代码

https://developers.weixin.qq.com/s/Wa8fsymT7oAU

// index.ts
// 获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    iptVal: '初始值',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,
    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
    tempFilePaths: [],
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs',
    })
  },
  onLoad() {
    // @ts-ignore
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile() {
    // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e: any) {
    // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },


  chooseImg() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success (res) {
        // tempFilePath可以作为 img 标签的 src 属性显示图片
        const tempFilePaths = res.tempFilePaths
      }
    })
  },
  onInput (e) {
    const value = e.detail?.value;
    console.log('onInput',value)
    this.setData({
      iptVal: value
    });
  }
})



最后一次编辑于  2022-07-06
回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员-Jahozheng
    社区技术运营专员-Jahozheng
    2022-07-07

    拍照内存占用过大,引起页面被系统回收

    2022-07-07
    有用
    回复
  • Demons
    Demons
    2022-07-06

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2022-07-06
    有用
    回复
登录 后发表内容