


Example of how WeChat applet obtains loop element id and wx.login login operation
This article mainly introduces the relevant information of the WeChat applet to obtain the loop element id and the wx.login login operation. Here are examples to help you implement this function. Friends who need it can refer to it
WeChat applet obtains the id of the loop element and the wx.login login operation
Get the id of the loop data element through the click method. Example:
In wxml:
<view id="list" wx:for="{{txt}}" > <text id="L_name">{{item.name}}</text> <text id="L_price">¥{{item.price}}/{{item.unit}}</text> <text id="L_place">{{item.place}}</text> <text id="L_date">(数据更新时间:{{item.date}})</text> <a catchtap="gotoresult" id="{{item.name}}" class="button">肉产类</a> </view>
The id of the a tag above is obtained through looping. JS can obtain the currently clicked element id through catchtap="gotoresult". In js:
gotoresult:function(e){ var ep = e.target.id console.log(ep); }
Mini program user login wx.login operation
js:
##
wx.login({ success: function (res) { if (res.code) { //发起网络请求 wx.request({ url: 'https://api.weixin.qq.com/sns/jscode2session', //url: 'https://www.xxx你的服务器网站xxxxxx.cn/', data: { appid:"你的appid", secret: "获取的secret", js_code: res.code, grant_type:"authorization_code" }, success:function(res){ message=res.data; console.log(message.openid)//返回的res里有用户openid等私密信息 } }) } else { console.log('获取用户登录态失败!' + res.errMsg)//异常反馈 } } });Through the above method, you can send a request to WeChat to obtain the information Returned openid and other information; The applet can determine whether the login has expired through wx.checkSession
wx.checkSession({ success: function(){ //session 未过期,并且在本生命周期一直有效 }, fail: function(){ //登录态过期 wx.login() //重新登录 .... } })If the login expires, you can call we.login above to log in
The above is the detailed content of Example of how WeChat applet obtains loop element id and wx.login login operation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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),
