方法
function selecImg ( page_that, cb_key, count) { console. log ( "选择图片" ) ; wx. chooseImage ( { count: count, sizeType: [ 'compressed' ] , sourceType: [ 'album' , 'camera' ] , success: function ( res) { console. log ( res) var pathArray = [ ] ; var PicNums = res. tempFiles. length; for ( var inta = 0 ; inta < PicNums; inta++ ) { var size = res. tempFiles[ inta] . size; var path = res. tempFiles[ inta] . path; var formatImage = path. split ( "." ) [ ( path. split ( "." ) ) . length - 1 ] ; console. log ( "图片格式" + formatImage) if ( formatImage != "png" && formatImage != "jpg" && formatImage != "jpeg" ) { return wx. showToast ( { title: '只能上传.png、.jpg、.jpep 格式' , icon: 'none' , image: '' , duration: 2000 , mask: true , } ) } if ( config. image_size < size) { return wx. showToast ( { title: '图片大小限制:' + ( config. image_size / 1024 / 1024 ) + "MB" , icon: 'none' , image: '' , duration: 1500 , mask: true , } ) } pathArray. push ( path) ; if ( inta == PicNums- 1 ) { var cb = { } ; cb[ cb_key] = pathArray; page_that. setData ( cb) ; } } } } )
}
.wxml
< image src= "../../Image/bg_pic1.png" mode= 'widthFix' style= "width:100px" bindtap= 'Oncarm' data- whopic= 'idcard' > < / image>
.js 调用
Oncarm: function ( e) { var whopic = e. currentTarget. dataset. whopic; util. selecImg ( this , whopic, 1 ) ; } ,