|
一、使用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, // 最多可以選擇的圖片張數(shù),默認(rèn)9
-
sizeType: ['original', 'compressed'], // original 原圖,compressed 壓縮圖,默認(rèn)二者都有
-
sourceType: ['album', 'camera'], // album 從相冊(cè)選圖,camera 使用相機(jī),默認(rèn)二者都有
-
success: function(res){
-
// success
-
console.log(res)
-
_this.setData({
-
src:res.tempFilePaths
-
})
-
},
-
fail: function() {
-
// fail
-
},
-
complete: function() {
-
// complete
-
}
-
})
-
}
二、圖片路徑進(jìn)行數(shù)據(jù)綁定
-
<view class="container">
-
<view>
-
<button type="default" bindtap="gotoShow" >點(diǎn)擊上傳照片</button>
-
</view>
-
<view>
-
<image class= "show-image" mode="aspectFitf" src="{{src}}"></image>
-
</view>
-
</view>
號(hào)外: 1、wx.chooseImage 調(diào)用相機(jī)或相冊(cè) 2、<image class= "show-image" mode="aspectFitf" src="{{src}}"></image>數(shù)據(jù)綁定 3、js中動(dòng)態(tài)修改文件路徑
-
var _this = this
-
wx.chooseImage({
-
count: 9, // 最多可以選擇的圖片張數(shù),默認(rèn)9
-
sizeType: ['original', 'compressed'], // original 原圖,compressed 壓縮圖,默認(rèn)二者都有
-
sourceType: ['album', 'camera'], // album 從相冊(cè)選圖,camera 使用相機(jī),默認(rèn)二者都有
-
success: function(res){
-
// success
-
console.log(res)
-
_this.setData({
-
src:res.tempFilePaths
-
})
-
},
-
fail: function() {
-
// fail
-
},
-
complete: function() {
-
// complete
-
}
|