这个报错是咋回事?
// pages/news/news-detail/news-detail.js
var postsData = require('../../../data/posts-data')
Page({
/**
* 页面的初始数据
*/
data: {
collected:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var postId = options.id;
this.data.currentPostId = postId;
var postData = postsData.postList[postId];
this.setData({
...postData
})
var postsCollected = wx.getStorageSync('postsCollected')
if (postsCollected) {
var postCollected = postsCollected[postId]
if (postCollected) {
this.setData({
collected: postCollected
})
}
}
else {
var postsCollected = {};
postsCollected[postId] = false;
wx.setStorageSync('postsCollected', postsCollected);
}
},
onColletionTap: function (event) {
var that = this;
var postsCollected = wx.getStorageSync('postsCollected')
var collected = postsCollected[this.data.currentPostId]
wx.showModal({
title: "收藏",
content: collected ? "是否取消收藏" : "是否收藏",
showCancel: "true",
cancelText: "取消",
cancelColor: "#333",
confirmText: "确认",
confirmColor: "#405f80",
success: function (res) {
if (res.confirm) {
collected = !collected
postsCollected[that.data.currentPostId] = collected
wx.setStorageSync('postsCollected', postsCollected)
that.setData({ collected })
}
}
})
}
})
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 622 份
- 解答问题 6815 个
微信带火了小程序,也让前端工程师有了更多的展现机会,本阶段带你从移动基础知识的学习到webAPP开发,及小程序开发,让你PC端与移动端两端通吃。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星