微信小程序 通过删除按钮已经删除了,但是重新进入后删除的又出现了是怎么回事呢?
Delete: function (event) {//删除代码
var position = event.currentTarget.id
// console.log("delete: " +position)
var tempTask = this.data.desArr.splice(position, 1);
this.setData({
desArr: this.data.desArr
})
var link = "删除成功"
wx.setStorageSync("01", this.data.desArr);
wx.setClipboardData({
data: link,
success: function (res) {
wx.showToast({
title: '删除成功',
icon: 'success'
})
}
})
},
整个js代码块
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
today: '',//当天日期
image: '/images/eaef35dd160a667ff53b1778e8baf4b6.jpg',//背景图片
desArr: []//数据源数组
},
//Zha: 取得时间日期信息
getNowFormatDate() {
//获取当天日期
var date = new Date();
var seperator1 = "-";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
return currentdate;
},
//Zha: 点击进入添加note的详细界面
newButton() {
//跳转页面
wx.switchTab({
url: '/pages/ssj/indexssj/indexssj'
})
wx.redirectTo({
url: '/pages/ssj/indexssj/indexssj',
})
},
onLoad: function (options) {
//-监听页面加载
//获取缓存内容
this.setData({
desArr: wx.getStorageSync('oldText')
})
if (this.data.desArr == null && this.data.desArr == '') {
//如果没有缓存则为空
this.setData({
desArr: []
})
}
//获取当天日期
var day = this.getNowFormatDate()
this.setData({
today: day
})
},
Delete: function (event) {
var position = event.currentTarget.id
// console.log("delete: " +position)
var tempTask = this.data.desArr.splice(position, 1);
this.setData({
desArr: this.data.desArr
})
var link = "删除成功"
wx.setStorageSync("01", this.data.desArr);
wx.setClipboardData({
data: link,
success: function (res) {
wx.showToast({
title: '删除成功',
icon: 'success'
})
}
})
},
onShow: function () {
// 生命周期函数--监听页面显示
//获取当前缓存
var arrayA = wx.getStorageSync('oldText');
var isChange = wx.getStorageSync('isChange');
if (arrayA.length != this.data.desArr.length) {
//如果数量改变从新赋值
this.setData({
desArr: arrayA
})
} else if (isChange == 1) {
wx.setStorageSync('isChange', 0);
this.setData({
desArr: arrayA
})
}
},
onShareAppMessage: function () {
// 用户点击右上角分享
return {
title: '文笔记+', // 分享标题
desc: '我们的功能不仅笔记', // 分享描述
path: 'path' // 分享路径
}
},
cancelTap(e) {
//删除按钮
console.log(e)
}
})