選擇圖片時可設置圖片是否是原圖,圖片來源。這用的也挺常見的,比如個人中心中設置頭像,可以與wx.upLoadFile()API使用
主要方法:
wxml
<button type="primary" bindtap="listenerButtonChooseImage">點擊我選擇相冊button><image src="{{source}}" mode="aspecFill" style="width: 640rpx; height: 640rpx"/>
js
Page({ data:{ // text:"這是一個頁面" source: '' }, /** * 選擇相冊或者相機 配合上傳圖片接口用 */ listenerButtonChooseImage: function() { var that = this; wx.chooseImage({ count: 1, //original原圖,compressed壓縮圖 sizeType: ['original'], //album來源相冊 camera相機 sourceType: ['album', 'camera'], //成功時會回調 success: function(res) { //重繪視圖 that.setData({ source: res.tempFilePaths }) } }) },
這又是一個奇葩API真實搞不懂怎么用這個。先模仿下官方咋使用但是沒有效果,搞懂了在補充下自己的使用
wxml
<button type="primary" bindtap="listenerButtonPreviewImage">展示圖片button>
js
var app = getApp()
Page({
data: {
banner:['../images/big.png', '../images/big.png', '../images/big.png'],
modalHidden: true
},
tapMove:function(e){
this.setData({
num: e.detail.current+1
})
},
/**
* 預覽圖片
*/
listenerButtonPreviewImage: function() {
wx.previewImage({
current: '../images/big.png',
//這根本就不走
success: function(res) {
console.log(res);
},
//也根本不走
fail: function() {
console.log('fail')
},
complete:function(){
console.log('complete')
}
})
},
onLoad: function () {
var that = this;
that.setData({
num:1,
count:that.data.banner.length
})
}
})