您的位置:首页 > 移动开发 > 微信开发

微信小程序 chooseImage选择图片或者拍照

2017-04-07 10:54 441 查看

微信小程序 chooseImage选择图片或者拍照

一、使用API wx.chooseImage(OBJECT)

var util = require('../../utils/util.js')
Page({
data:{
src:"../image/pic4.jpg"
},
gotoShow: function(){var _this = this
wx.chooseImage({
count: 9, // 最多可以选择的图片张数,默认9
sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
success: function(res){
// success
console.log(res)
_this.setData({
src:res.tempFilePaths
})
},
fail: function() {
// fail
},
complete: function() {
// complete
}
})
}
 

二、图片路径进行数据绑定

<view class="container">
<view>
<button type="default" bindtap="gotoShow" >点击上传照片</button>
</view>
<view>
<image class= "show-image" mode="aspectFitf" src="{{src}}"></image>
</view>
</view>

号外:

  1、wx.chooseImage 调用相机或相册
  2、<image class= "show-image" mode="aspectFitf" src="{{src}}"></image> 数据绑定
  3、js中动态修改文件路径

var _this = this
wx.chooseImage({
count: 9, // 最多可以选择的图片张数,默认9
sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
success: function(res){
// success
console.log(res)
_this.setData({
src:res.tempFilePaths
})
},
fail: function() {
// fail
},
complete: function() {
// complete
}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐