需求:

       通过点击上传照片按钮(提供两种模式:1、从相册获取图片;2、拍照获取图片),实现获取照片后,照片以及照片的文字说明(也就是代码中的userInfo数据)能够显示在小程序页面上。


问题:

       从相册获取图片的方式,是可以实现图片和文字展示在页面上的,但是拍照获取图片的方式,不能实现 上述效果(偶尔可以显示),数据是采用setData刷新的,页面也绑定了userInfo数据,现在不知道为什么拍照的方式出现的问题。


测试手机:iphone 6plus


核心代码:

  index.js

Page({

   data: {

       motto: '上传靓照',

       userInfo: {}

   },

//事件处理函数

uploadImage: function() {

   var that = this

   wx.chooseImage({

    success: function(res) {

       var tempFilePaths = res.tempFilePaths

       console.log(res);

       wx.showToast({

           title: '鉴定中,请稍候',

           icon: 'loading',

           duration: 2000

       })

       that.setData({

           userInfo: {

           //填充人脸识别界面的图片

           imageUrl: tempFilePaths[0],

           tips: '人脸识别中...'

           }

       })

   }

})

},

onLoad: function () {

   console.log('onLoad')

}

})


index.wxml

<view class="container">

   <view class="userinfo">

       <image class="userinfo-avatar" mode="aspectFit" src="{{userInfo.imageUrl}}" background-size="cover">image>

   <text class="userinfo-tips">{{userInfo.tips}}text>

   view>

   <view class="usermotto">

       <button class="button" type="primary" bindtap="uploadImage">{{motto}}button>

   view>

view>


index.wxss

/**index.wxss**/

.userinfo {

display: flex;

flex-direction: column;

align-items: center;

}

<

展开全部
收起
1回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • 有无

    16人对此回答表示赞同

    急求呀,求大佬告知,以上代码可直接运行

    展开
    16
    0回复
    发布于 6年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部