当前位置:网站首页>Wechat applet learning record
Wechat applet learning record
2022-06-11 05:36:00 【Cockroach bully BBQ】
Originally js Follow h5 Can also understand the level of , Can't write , I thought small programs were very difficult , I've been in touch with , Record keeping .
The functions you do are as follows :1, Login screen 2, Network request 3, The list shows 4,item Click on 5, Image loading 6, Drop down to refresh data 7, Pull up to load data 8, Verification code function 9, Bottom popup list item Click Select 10, Page Jump and value transfer
Look at the interface , It's ugly , Anyway, I don't have any design drawings , Just look at the function ……



1, Login screen Write your own style The layout has row and column Namely Android in LinnerLayout Horizontal and vertical
<view class="itemview">
<text> full name :</text>
<input class="inputText" name="username" placeholder=" Please enter a name " bindinput="inputusername" maxlength="6" />
</view>
<view class="itemview">
<text> password :</text>
<input class="inputText" name="userpassword" placeholder=" Please input a password " bindinput="inputuserpassword" maxlength="6" />
</view>
Through this property bindinput Can be in js Get the input content in as follows
inputusername: function (e) {
// Assign the value of the entered user name to the global data Medium username And then click login Click the global button data Medium username The same goes for passwords
this.setData({
username: e.detail.value
})
},
2, Network request and value according to key ( Here's the request https://www.weather.com, You need to go to the development settings in the background -- Interface settings add , Jump to the applet's web-view Medium url You also need to add configurations ,tip: Jump web-view This url The configuration will fail occasionally ....)
var that = this;
wx.request({
url: 'https://www.weather.com.cn/data/sk/101010100.html',
data: {},
// method: "POST",
header: {
'content-type': 'json' // The default value is
// 'content-type':'application/x-www-form-urlencoded'
},
success: function (res) {
console.log(res.data.weatherinfo.sm) // Take that one . That'll do
}
})
},
3, The list shows
<view class="itemscroll" wx:for="{ {listData}}" wx:key="index" style="display:flex;flex-direction:column" bindtap="clickItem" data-bean="{ {index}}">
<text class="name">{ {item.name}}</text>
<image class="img" src="{ {item.img}}" mode="scaleToFill"></image>
<text class="info">{ {item.info}}</text>
<view class="linered"></view>
</view>
wx:for Is the key to rendering a list
4,item Click and transfer values Click events registered above bindtap="clickItem" Click to get index The key is data-bean="{ {index}}" , then
// Get the index
clickItem: function(e){
var that = this;
var index = e.currentTarget.dataset.bean;
},
// Put a parameter ( example url) Pass to next page
url: '../webview/webview?url='+that.data.listData[index].url,
5, Image loading What I'm talking about here is using local images
When you want to use this picture page Next newly build image Folder Put the picture in , And then in wxml It is OK to use it in
<view>
<image src='image/bg.png' class="imagetset"></image>
</view>
6, Drop down to refresh data
In the... To add a drop-down refresh page Of json Add... To the file "enablePullDownRefresh": true as follows
"usingComponents": {},
"enablePullDownRefresh": true
And then in
/**
* Page related event handler -- Monitor user pull-down action
*/
onPullDownRefresh: function () {
wx.showNavigationBarLoading() // Show load... In the title bar
// simulation 3s Asynchronous operation of pull-down refresh Stop the pull-down refresh when finished
this.setData({
// Do not show the bottom add that is requesting data and has no more data
showloading:false,
showloaded:false,
})
this.jishiqi() // The countdown mimics the operation of the asynchronous request interface jishiqi This function needs to be written on top of this function
},
jishiqi : function (){
var that = this;
var num = 3;
// var datanews = [];
var addData = [{name:" I am me ",img:"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607331222108&di=2ce09338277db412ca8950ee82ed5ea9&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201810%2F08%2F20181008185834_sgnqc.jpg",info:" Xiao Xin painting an elephant ",url:"https://lol.qq.com/guides/detail.shtml?ADTAG=cooperation.glzx.web&name=Annie&line=mid"}];
var timer = setInterval(function () {
num--;
if (num <= 0) {
console.log(" Finished loading ");
clearInterval(timer);
wx.hideNavigationBarLoading() // Stop loading when finished
wx.stopPullDownRefresh();
// datanews.concat(addData);
that.setData({
// listData:that.data.listData.concat(addData)
listData:addData,
})
}
}, 1000)
},
7, Pull up to load data
/**
* Handling function of page pull bottom event
*/
onReachBottom: function () {
// Pull up and load three times Simulated paging load is complete No more requests
if(this.data.addcount >= 3){
this.setData({
showloading:false,
showloaded:true,
});
return;
}
var addData = [{name:" I am me 123456",img:"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607331222108&di=2ce09338277db412ca8950ee82ed5ea9&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201810%2F08%2F20181008185834_sgnqc.jpg",info:" Xiao Xin painting an elephant 123456",url:"https://lol.qq.com/guides/detail.shtml?ADTAG=cooperation.glzx.web&name=Annie&line=mid"}];
var that = this;
var num = 3;
var timer = setInterval(function () {
num--;
if (num <= 0) {
console.log(" Finished loading ");
clearInterval(timer);
wx.hideNavigationBarLoading() // Stop loading when finished
wx.stopPullDownRefresh();
that.setData({
listData:that.data.listData.concat(addData),
showloading:true,
showloaded:false,
addcount:that.data.addcount+1,
})
}
}, 1000)
},
8, Verification code function , Because I used it text Verification code displayed Out of commission button Of disable function So use global variables disabled To control the text Can I click ...
getyzm: function () {
var _this = this;
var num = 61;
if (!_this.data.disabled) {
var timer = setInterval(function () {
num--;
if (num <= 0) {
clearInterval(timer);
_this.setData({
codename: ' To resend ',
disabled: false,
fontcolor: '#f00'
})
} else {
_this.setData({
codename: num + "s",
disabled: true,
fontcolor: '#00f'
})
}
}, 1000)
}
},
9, Bottom popup list item Click Select
wx.showActionSheet({
// Write a bottom popup and click event
itemList: ['haha', 'baba'],
itemColor: '#f00',
success: function (res) {
if (res.tapIndex === 0) {
wx.showToast({
title: 'haha',
icon: "none",
})
} else if (res.tapIndex === 1) {
wx.showToast({
title: 'baba',
icon: "none",
})
}
},
fail: function (res) {
}
}),
10, Page Jump and value transfer I have only learned the most basic That is, by jumping url Pass value
toPageTest: function () {
// Write a jump to listView Interface
wx.navigateTo({ // navigateTo amount to android startActivity Medium activity The standard model
url: '../listpage/listpage?name=123&pwd=123456',
})
},
And then again listpage Interface onload Parameterized functions get
/**
* Life cycle function -- Monitor page loading
*/
onLoad: function (options) {
var op = options;
console.log(op.name +'is'+ op.pwd)// raymond is male
// Simulate requesting data for the first page
this.getFirstDataNetWork();
},
tip: Function callback ( Network request / Countdown, etc ), We all need to put this Conversion can be used , namely var thst = this; Otherwise, global variables cannot be accessed and assigned .
2020-12-16 ADD:
11. Global variable definition and use
In the project app.js The following is added :
globalData: {
userInfo: null,
hasLogin: "false",
opnid: null
},
stay page When used inside, it is on the top (page Outside the curly braces ) Write :
const app = getApp()
Then when you use it, it's OK use app Instead of this
app.globalData.userInfo
12. Bottom switch tab Use ( Must be greater than or equal to 2 individual Less than or equal to 5 individual )
In the project app.json Add the following , Configuration page Switch back and forth icon 、 Font color and tab Corresponding page
"tabBar": {
"color": "#a9b7b7",
"selectedColor": "#f00",
"borderStyle": "black" ,
"list": [{
"selectedIconPath": "imgages/bg.png",
"iconPath": "imgages/bg.png",
"pagePath": "pages/index/index",
"text": " home page "
}, {
"selectedIconPath": "imgages/bg.png",
"iconPath": "imgages/bg.png",
"pagePath": "pages/listpage/listpage",
"text": " list "
},{
"selectedIconPath": "imgages/bg.png",
"iconPath": "imgages/bg.png",
"pagePath": "pages/bannerpage/bannerpage",
"text": " Shuffling figure "
}
]
}
边栏推荐
- 【深入kotlin】 - 初识 Flow
- Introduction to coordinate system in navigation system
- 2021-04-19
- code
- WinForm (I) introduction to WinForm and use of basic controls
- English digital converter
- Exploration of kangaroo cloud data stack on spark SQL optimization based on CBO
- 20多种云协作功能,3分钟聊透企业的数据安全经
- NDK learning notes (IV) functions, classes and exceptions of swig
- Bit operation marks multiple switches with one parameter
猜你喜欢

Basics of customized view

WinForm (II) advanced WinForm and use of complex controls

NDK learning notes (12) native graphics API, using avilib to create an avi video player

WinForm (I) introduction to WinForm and use of basic controls

初步了解多任务学习

NDK learning notes (XI) POSIX sockect local communication

【入门级基础】Node基础知识总结

1. use alicloud object OSS (basic)

Vins fusion GPS fusion part

(15) Infrared communication
随机推荐
AttributeError: ‘HistGradientBoostingClassifier‘ object has no attribute ‘_ n_ features‘
Multi thread tutorial (XXIX) immutable design
工具类ObjectUtil常用的方法
使用acme.sh自动申请免费SSL证书
[entry level basics] node basic knowledge summary
MySQL string to array, merge result set, and convert to array
Combien de courant le câblage des PCB peut - il supporter?
NDK R21 compiles ffmpeg 4.2.2 (x86, x86_64, armv7, armv8)
Section III: structural characteristics of cement concrete pavement
Analyze while doing experiments -ndk article -jni uses registernatives for explicit method registration
Section II: structural composition characteristics of asphalt pavement (2) structural layer and performance requirements
Preliminary understanding of multi task learning
js promise,async,await简单笔记
Getbackgroundaudiomanager controls music playback (dynamic binding of class name)
NDK learning notes (IX) POSIX sockect connection oriented communication
深度学习分布式训练
Multi threading tutorial (XXIV) cas+volatile
点击图标不灵敏咋整?
MySQL nested sorting: first sort and filter the latest data, and then customize the sorting of this list
Zed2 camera calibration -- binocular, IMU, joint calibration