class infoget { constructor() { this.likeList = localStorage.getItem("list") == null ? [] : JSON.parse(localStorage.getItem("list")); this.currentifo = {}, this.infoSevice() } async infoSevice () { var res = await infoSevice.infoSevice({ page:1, id:GetUrlParam("id"), t:GetUrlParam("name"), }); this.currentifo = res $(".action").append(` 写真集详情 `) res.data.forEach((v) =>{ $(".info").append(`
${v.title}
`) }) this.like(); } like() { var isHave = this.likeList.filter((items,index) => { // console.log(items) if (item.data != this.currentifo.data) { // console.log(this.currentifo.data[0].title) return items } }); isHave.forEach((v,i)=>{ console.log(v.title) console.log(this.currentifo.data[i].title) if (v.title = this.currentifo.data[i].title) { $(".likeicon").removeClass("icon-xin").addClass("icon-aixin"); } }) // 切换收藏 与 取消收藏 $('.likeicon').on('click', () =>{ // console.log(this.currentifo) if ($(".likeicon").hasClass("icon-xin")) { $(".likeicon").removeClass("icon-xin ").addClass("icon-aixin"); this.likeList.push(this.currentifo) // console.log(this.likeList) localStorage.setItem("list", JSON.stringify(this.likeList)) } else { $(".likeicon").removeClass("icon-aixin ").addClass("icon-xin"); this.likeList = this.likeList.filter((item,index) => { // console.log("item.data",item.data) // console.log("this.currentifo.data",this.currentifo.data) if (item.data !== this.currentifo.data) { return item } // console.log(item) }); localStorage.setItem("list", JSON.stringify(this.likeList)) } }) } } function GetUrlParam(paraName) { var url = document.location.toString(); var arrObj = url.split("?"); if (arrObj.length > 1) { var arrPara = arrObj[1].split("&"); var arr; for (var i = 0; i < arrPara.length; i++) { arr = arrPara[i].split("="); if (arr != null && arr[0] == paraName) { return arr[1]; } } return ""; } else { return ""; } } new infoget();