//index.js
//获取应用实例
const app = getApp()
/**index.js**/
Page({
data: {
imgpath:"../../images/1.png"
},
ViewTap:function(){
var that=this;
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths
that.setData({ imgpath: tempFilePaths[0] })
}
})
},
})
不同文件
<!--index.wxml-->
<view class="apidemo">
<image src="{{imgpath}}" class="img" bindtap="ViewTap"></image>
<image src="../../images/4.png" class="img"></image>
<image src="../../images/5.png" class="img"></image>
</view>
不同文件
/**index.wxss**/
.apidemo{
display:flex;
flex-direction:column;
align-items:center;
}
.img{
height:120rpx;
width:120rpx;
}