多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ## ***.js ``` Page({ data:{ isEmpty:true }, onLoad(){ var image = wx.getStorageSync('image'); if (image){ var imgUrl = image.imgUrl[0]; var isEmpty = image.isEmpty; this.setData({ imgUrl, isEmpty }) } }, click(){ wx.chooseImage({ count: 9, // 默认为9 sizeType: ['original', 'compressed'], // 指定原图或者压缩图 sourceType: ['album', 'camera'], // 指定图片来源 success: (res)=> { var tempFilePaths = res.tempFilePaths wx.setStorageSync('image',{ imgUrl: tempFilePaths, isEmpty: false }); var image = wx.getStorageSync('image'); var imgUrl = image.imgUrl[0]; var isEmpty = image.isEmpty; this.setData({ imgUrl, isEmpty }) } }) } }) ``` ## ***.wxml ``` <view class="my"> <image src="{{isEmpty?'/images/iqiyi.png':imgUrl}}" catchtap='click' mode="aspectFill"></image> <text>A day is a miniature of eternity. </text> </view> ``` ## ***.wxss ``` .scroll-view{ /* width: 100%; */ padding: 20rpx; display: flex; white-space: nowrap; } image{ width: 200px; height: 200px; margin: 30px; border-radius: 50%; } text{ max-width: 300px; text-align: center; line-height: 24px; font-size: 30rpx; } view{ display: flex; justify-content: center; align-items: center; flex-direction: column } ```