当前位置:网站首页>[wechat applet development (IV)] applet fast actual combat classic problem navigation
[wechat applet development (IV)] applet fast actual combat classic problem navigation
2022-07-24 08:15:00 【Sock is a dog】
List of articles
- Preface
- One 、[wx:key The use of and wx:key Value ](https://developers.weixin.qq.com/miniprogram/dev/reference/wxml/list.html#wx:key)
- Two 、wx:for Usage of
- Two 、 Click event binding and parameter transfer
- 3、 ... and 、 About WeChat applet style Dynamic binding problem
- Four 、 The parent component dynamically transfers values to the child component
- 5、 ... and 、 Get the dynamic distance to scroll up
- 6、 ... and 、 The child component calls the method of the parent component
- 7、 ... and 、 How does wechat applet realize page parameter transmission ?
- 8、 ... and 、 The solution to the problem of clicking repeatedly to jump to the page in wechat applet
- Nine 、style Binding dynamic background background-size invalid
Preface
Tips : WeChat api More detailed in the document , Have the energy to read directly , This content is only for navigation summary
Tips : The following is the main body of this article , The following cases can be used for reference
One 、wx:key The use of and wx:key Value
Example : and vue Of :key Basically consistent There will be warning Tips
In general use
wx:key="unique"
character string , On behalf of the for Cyclic array in item One of the property, The property The value of needs to be a unique string or number in the list , And can't change dynamically .
Reserved keyword *this On behalf of the for In the loop item In itself , This expression requires item Itself is a unique string or number .
Two 、wx:for Usage of
And just in the same document ,wx:for and vue The difference is , He needs to specify the name of the loop variable and index, That is to say vue Medium (item,index)in list
Use wx:for-item You can specify the variable name of the current element of the array ,
Use wx:for-index You can specify the variable name of the array's current subscript
<view wx:for="{
{array}}" wx:for-index="idx" wx:for-item="itemName">
{
{
idx}}: {
{
itemName.message}}
</view>
Two 、 Click event binding and parameter transfer
<view>{
{ msg }}</view>
<button bindtap="clickMe"> Click on the I </button>
Page({
clickMe: function() {
this.setData({
msg: "Hello World" })
}
})
2 bindtap Pass parameters
<view bindtap="goTo" data-index={
{item.index}}>
goTo: function(e){
// Parameters passed
const index= e.currentTarget.dataset['index'];
}
3、 ... and 、 About WeChat applet style Dynamic binding problem
Here we need to have a template occupying idea class The same is true of dynamic binding Include animation
style="z-index:{
{card.zIndex?card.zIndex:199 - card_index}}"
Four 、 The parent component dynamically transfers values to the child component
The parent component normally passes a dynamic variable
<nav-bar title=" meditation " scrollTop="{
{scrollTop}}"></nav-bar>
Child components Monitor processing observer: ‘update’,
// component/navBar/navBar.js
Component({
/** * A list of properties of a component */
properties: {
scrollTop: {
type: String,
value: '0',
observer: 'update',
}
},
/** * A list of methods for a component */
methods: {
update(newValue) {
let op = 0;
if (newValue != 0 && newValue <= 40) {
op = newValue / 40
}
if (newValue >= 40) {
op = 1;
}
this.setData(
{
opacity: op
}
)
},
}
})
5、 ... and 、 Get the dynamic distance to scroll up
onPageScroll(t) {
this.setData({
scrollTop: t.scrollTop
})
}
6、 ... and 、 The child component calls the method of the parent component
Child components call init Pass parameters
this.triggerEvent('init', this.data.voiceArr[this.data.currentSelectIndex]);
Parent component binding bind:init Realization changeVoiceInit Method
<change-voice bind:closeVoiceShow="closeVoiceShow" bind:changeVoice="changeVoice" bind:init="changeVoiceInit" index="6"></change-voice>
7、 ... and 、 How does wechat applet realize page parameter transmission ?
After the incoming connection is required add to Parameters ?type=
wx.navigateTo({url: e.currentTarget.dataset[‘link’] + ‘?type=’+e.currentTarget.dataset[‘type’]+‘&index=’+e.currentTarget.dataset[‘index’]})
onLoad: function(options) {
// options.type Can get similar query
}
8、 ... and 、 The solution to the problem of clicking repeatedly to jump to the page in wechat applet
You can also use the throttling function , Make a mark 1 Only once per second
this.data.navigateToFlag = true;
setTimeout(()=>{
this.data.navigateToFlag = false;
},1000)
wx.navigateTo({
url: '/pages/result/index?times=29&type=3&content= breathing '})
Nine 、style Binding dynamic background background-size invalid
hold background-size It can also be placed after binding
<view class="container" style="background: url('{
{currentVoice.img}}') no-repeat;background-size: 100% 100%;">
边栏推荐
- mysql使用explain分析sql执行计划帮助查找性能瓶颈
- Intelligent robot and intelligent system (Professor Zhengzheng of Dalian University of Technology) -- 5. Bionic robot
- Implementation of unity hub free version
- 33-SparkSql的介绍、DataFrame和DataSet
- [Game Collection] mobile phones are about to burst, and a collection of six high-quality pyGame games is coming ~ (source code attached)
- MySQL -- subquery scalar subquery
- 基于thinkphp将execle表格上传并插入数据库
- The vision group of Hegong University Sky team trained Day1 - machine learning, and learned to use the Yolo model
- Detailed notes on pytoch building neural network
- Intelligent robots and intelligent systems (Professor Zhengzheng of Dalian University of Technology) -- 4. Autonomous robots
猜你喜欢

Vidar-Team战队专访:AS WE DO, AS YOU KNOW.

VIDAR team team exclusive interview: as we do, as you know

The code is tired. Stop and enjoy the top color matching~

As skillfully uses idea annotation to improve collaboration / development efficiency

Robot operation continuous learning thesis (1) original text reading and Translation -- primitive generation strategy learning without catastrophic forgetting in robot operation

Markdown basic grammar learning

Wechat applet file types and functions

Do you want to have a robot that can make cartoon avatars in three steps?

FPGA综合项目——图像边缘检测系统

Figure New Earth: how to import CAD files with modified elevation datum (ellipsoid)
随机推荐
Robot operation continuous learning thesis (1) original text reading and Translation -- primitive generation strategy learning without catastrophic forgetting in robot operation
[internationalization] decimal point and comma of application development
赛宁TechTalk丨攻防演练:攻击组合拳 “稳准狠”渗透
Learn - use do... While loop according to the formula e=1+1/1+ 1/2!+ 1/3!+…+ 1/n! Calculate the value of E (accuracy is 1e-6)
Intelligent robots and intelligent systems (Professor Zheng Zheng of Dalian University of Technology) -- 1. robots and mobile robots
Kotlin coprocess analysis (III) -- understanding the context of coprocess
33-SparkSql的介绍、DataFrame和DataSet
Wechat payment V3 version of openresty implementation and pit avoidance Guide (service side)
Saining Techtalk attack and defense drill: attack combination fist "stable, accurate and ruthless" penetration
EZDML reverse engineering import database analysis practical operation tutorial
Database system - Basic Concepts
Adaptive problem of img aspect ratio scaling in flex layout in Safari
Kotlin coroutine (I): foundation and deepening
Do you want to have a robot that can make cartoon avatars in three steps?
Why is knowledge base important? This is the best answer I've ever heard
[wechat applet development] (III) homepage banner component uses swiper
Error reported by Nacos: error Nacos failed to start, please see d:\nacos\logs\nacos log for more details.
Kotlin coroutine (II): scope and cancellation
VIDAR team team exclusive interview: as we do, as you know
Continuous learning, lifelong learning, episodic memory, memory module paper summary -- gradient episodic memory promotes continuous learning