企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## wxml ``` //给分享收藏 <image src="{{shared?'/images/icon/share.png':'/images/icon/share-anti.png'}}" catchtap='onShare'/> <image src="{{collected?'/images/icon/collection.png':'/images/icon/collection-anti.png'}}" catchtap='onCollect' /> ``` ## js ``` Page({ /** * 页面的初始数据 */ data: { collectd:false, shared:false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var id = options.id var data = local.postList[id]; this.setData({ data, postId:id, }) // 1.有缓存则取值,没有缓存则创建缓存 let allCollected = wx.getStorageSync('allCollected'); if (allCollected) { let storageCollected = allCollected[id]; this.setData({ collected: storageCollected }) } else { let allCollected = {}; allCollected[id] = false; wx.setStorageSync('allCollected', allCollected) }; }, onCollect() { var allCollected = wx.getStorageSync('allCollected'); var storageCollected = allCollected[this.data.postId]; storageCollected = !storageCollected; allCollected[this.data.postId] = storageCollected; wx.setStorageSync('allCollected', allCollected); this.setData({ collected: storageCollected }) }, onShare(){ wx.showActionSheet({ itemList: ["分享到微信", "分享到微博", "分享到朋友圈"], itemColor: '#ff2d51', success:res=>{ console.log(res.tapIndex); this.setData({ shared: true }) }, fail: err => { this.setData({ shared: false }) } }) }, }) ```