


Recently, when developing small programs in the group, we encountered an eternal topic on the front end: page value passing
We just started to use path parameter passing to solve the problem, but as we all know:
Each browser HTTP The maximum length of the Get request URL is not the same. The maximum length of several commonly used browsers and the submission situation after exceeding the maximum length are as follows:
IE6.0: The maximum length of the URL is 2083 characters, and it cannot be submitted after exceeding the maximum length.
IE7.0: The maximum length of URL is 2083 characters. It can still be submitted after exceeding the maximum length, but only 2083 characters can be passed.
firefox 3.0.3: The maximum URL length is 7764 characters. It cannot be submitted after the maximum length is exceeded.
Opera 9.52: The maximum length of URL is 7648 characters. It cannot be submitted after the maximum length is exceeded.
Google Chrome 2.0.168: The maximum length of the URL is 7713 characters. It cannot be submitted after the maximum length is exceeded.
So I don’t think it’s reliable.
After researching the official website, I found that there are two ways to do this "more elegantly", which of course cannot be compared with vuex/flux.
-
Use global variables
Define in the projectapp.js
globalData
App({ globalData:{ userInfo:'angeladaddy' } });
Use where needed :
getGlobalVar:function(){ var that=this; that.setData({ globalvar_str:JSON.stringify(getApp().globalData) }) }
Of course, you can also assign a value at any time:
onLoad:function(options){ getApp().globalData.userInfo+=' is an awesome man'; },
Effect:
According to the official introduction:
First define the template, use the name attributeThis solves the problem of page value transfer in a "duang~~~" way<template name="msgItem"> <view> <text> {{index}}: {{msg}} </text> <text> Time: {{time}} </text> </view> </template>Then, use the template
- Use the is attribute to declare the template you need to use, and then pass in the data required by the template, such as:
<template is="msgItem" data="{{...item}}"/>Assign a value to the item to display the template dataPage({ data: { item: { index: 0, msg: 'this is a template', time: '2016-09-15' } } })
Postscript: Since small programs can use all the features of ES6, then that var What the hell is that=this? Why can't we use arrow functions to solve scope problems? Try again later.
The above is the detailed content of Share a small exploration of value transfer on a WeChat applet page. 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

SublimeText3 English version
Recommended: Win version, supports code prompts!

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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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.

Atom editor mac version download
The most popular open source editor