🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## post-img.js ### 初始数据设置 ``` Page({ data: { isEmpty: true }, ``` ### 数据加载 ``` onLoad() { wx.setNavigationBarTitle({ title:'个人资料' }); var image = wx.getStorageSync('image'); if (image) { var imgUrl = image.imgUrl[0]; var isEmpty = image.isEmpty; this.setData({ imgUrl, isEmpty }) } var textValue = wx.getStorageSync('Text'); if (textValue) { this.setData({ inputValue: textValue, }) } else { } }, ``` ### 自定义re函数,输入框失焦恢复原始文本内容 ``` re(){ var text = wx.getStorageSync('Text'); this.setData({ inputValue:text, }) }, ``` ### 自定义onConfirm函数 ``` onConfirm(e) { var value = e.detail.value; wx.setStorageSync('Text', value); this.setData({ inputValue: value, }) }, ``` ### 选择图片函数 ``` click() { wx.chooseImage({ count: 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({ isEmpty: isEmpty, imgUrl }) } }) }, }) ```