search
HomeWeChat AppletMini Program DevelopmentAbout the implementation of WeChat mini program collection function

This article mainly introduces the implementation code of the WeChat applet collection function. The basic function is to display the collected items after clicking on the collection, and the currently clicked collection item will appear on another page. Friends who need it can refer to

Requirements

After clicking the collection, it will show that it has been collected, and the currently clicked collection will appear on another page. Project

Problems that need to be solved

  1. After clicking to favorite It needs to show that it has been collected, and the text status changes

  2. How does another page know that you clicked to collect, and get the data you clicked to collect

How to solve?

  1. Data state binding, and cached by state control style (ternary operator)

  2. (setStorageSync, getStorageSync), click on the page to set the cache (data id), display the page to obtain the cache, and by obtaining the cache id, take out the obtained id item in the entire data and put it into a new array

Specific implementation

wxml

<image class="save " src="{{isClick?&#39;../../youzan-image/save-s.png&#39;:&#39;../../youzan-image/save.png&#39;}}" bindtap="haveSave"></image>
   <text class="saveText">{{isClick?&#39;已收藏&#39;:&#39;收藏&#39;}}</text>

Click the page js

 Page({
  data: {
  job: [],
  jobList: [],
  id: &#39;&#39;,
  isClick: false,
  jobStorage: [],
  jobId: &#39;&#39;
  },
  haveSave(e) {
  if (!this.data.isClick == true) {
   let jobData = this.data.jobStorage;
   jobData.push({
   jobid: jobData.length,
   id: this.data.job.id
   })
   wx.setStorageSync(&#39;jobData&#39;, jobData);//设置缓存
   wx.showToast({
   title: &#39;已收藏&#39;,
   });
  } else {
   wx.showToast({
   title: &#39;已取消收藏&#39;,
   });
  }
  this.setData({
   isClick: !this.data.isClick
  })
  }
 })

to display the page js

import jobList from &#39;../../api/detail&#39;
Page({
 data: {
 id:&#39;&#39;,
 job:[],
 savejob:[],
 },
 onLoad: function (options) {
 console.log(wx.getStorageSync(&#39;jobData&#39;));
 let savejob = wx.getStorageSync(&#39;jobData&#39;)//获得缓存
 let index = savejob.length-1;
 console.log(savejob[index].id);
 let jobid = savejob[index].id
 let temp= jobList[jobid] //将获得缓存后匹配的数据放入新的数组
 let job= [];
 job.push(temp);
 this.setData({
  id:index,
  job: job,
 })
 },
})

The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

WeChat Mini Program implements the functions of liking, deleting lists and sharing

WeChat Mini Program Implementation of scrolling message notifications

WeChat applet dynamically displays the effect of project countdown

The above is the detailed content of About the implementation of WeChat mini program collection function. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft