当前位置:网站首页>Writing wechat applet with uni app
Writing wechat applet with uni app
2022-06-25 11:04:00 【Stranger & love sorrow】
Catalog
Basic configuration of the page
The life cycle function of the applet uni-app Compatible with
Enable / disable pull-down refresh
Customize the applet navigation bar
uni-app The routing Wechat applets are the same except for different prefixes
Basic configuration of the page
backgroundColor | Pull down the refreshed background color , The drop-down refresh part is the background |
backgroundTextStyle | Background text style of the applet Only light light colour and dark Dark Two values |
navigationBarBackgroundColor | The background color of the navigation bar |
navigationBarTitleText | The title text of the navigation bar |
navigationBarTextStyle | The text color of the navigation bar Only black black and white white Two values |
enablePullDownRefresh | Turn on the pull-down refresh function The default value is false |
onReachBottomDistance | The distance to trigger the bottom touch method The unit is px |
tabBar Set up
stay uni-app Medium pages.json To configure
"tabBar": {
"color": "#000000", // The font color
"selectedColor": "#d00", // Selected font color
"borderStyle": "black",
"backgroundColor": "#ffffff", // The background color
"position": "top", // Top tabBar, The default is bottom
"list": [{
"pagePath": "pages/index/index", // Page path
"text": " home page ",
"iconPath": "static/icon/shouye.png", // The color of the unselected icon
"selectedIconPath": "static/icon/pitch-icon/shouye.png"
},
}matters needing attention
1 tabBar At least two. , Up to five
2 The following font icons need two colors , Unselected and selected , It is recommended that after downloading , Use as a picture
3 When tabBar When set to the top , There will be no more icons , Only words
uni-app introduce vantUi
1 Built-in terminal npm install vant Applet version
2 newly build wxcomponents Folder , Copy @vant Inside dist Folder . And paste it and rename it vant
3 It can be deleted because vant Generated folder
4 Normal introduction vant what is needed , But the file path is “/wxcomponents/vant/.....”
5 stay pages.json in Modify the configuration . Make it usable vant and npm To configure , The specific code is as follows
Set dynamic top text
pages.json in , When creating a new file , The corresponding data will be automatically added , You can set the header text here , Can also be introduced vant The style of
"path": "pages/list/list",
"style": {
"navigationBarTitleText": " list ",
"enablePullDownRefresh": false,
"usingComponents": {
"van-icon": "/wxcomponents/vant/icon/index",
}
}encapsulation axios request
establish utils Folder , Add... To the folder http.js file
function axios({
url,
method = "get",
data = {}
}) {
uni.showLoading({
title: ' Desperately loading ...',
mask: true
})
return new Promise((resolve, reject) => {
uni.request({
url: "https://www.uinav.com/api/public/v1" + url,
method,
data,
success(res) {
resolve(res.data)
uni.hideLoading()
},
fail(err) {
reject(err)
uni.hideLoading()
uni.showToast({
title: " request was aborted "
})
}
})
})
}
export default axios
When using the page
introduce
import axios from '../../utils/http.js'Use
axios({ url: '/home/swiperdata'}).then(res => {
console.log(res)
})The life cycle function of the applet uni-app Compatible with
onLoad | Trigger when the page loads amount to vue Of created Life cycle |
onReady | Triggered when the page is first rendered amount to vue Of mounted Life cycle |
onShow | Page shows / Trigger when entering the front desk amount to vue Of activited |
onHide | Page hidden / Trigger when cutting into the background amount to vue Of deActivited |
onUnload | Trigger when the page is unloaded amount to vue Of destroyed Life cycle |
onPullDownRefresh | Drop down refresh hook function |
onReachBottom | Pull up to the loaded hook function |
Enable / disable pull-down refresh
uni.startPullDownRefresh() // Turn on the pull-down refresh function
uni.stopPullDownRefresh() // Stop the method of pull-down refresh
And in the wechat applet , It is wx.startPullDownRefresh()
Customize the applet navigation bar
1 On the page to be used pages It defines "navigationStyle":"custom"
2 Define a subcomponent , This sub component is the customized header navigation bar , In this component No, onLode, have access to mounted
uni.getSystemInfo({}) You can get the basic information of the mobile phone
statusBarHeight For the height of the mobile navigation bar
3 Use the page to import this component , You can normally use parent-child components to pass values
Be careful : If the click event does not take effect in this component , You can try to trigger a child to parent incoming event
uni-app Subcontracting of
1 pages Is the location of the page used by the applet , With it At the same level The location of , Create subcontracting folder , Create the corresponding file , The format is as follows

2 stay pages.json in , Configuration subcontracting
"subPackages": [{
"root": "packageOne",
"pages": [
{
"path": "search/search",
"style": {
"navigationBarTitleText": " Commodity search ",
"enablePullDownRefresh": true,
"backgroundColor": "#d00",
"onReachBottomDistance": 260
}
}
// Add another page here ,{path:....,style....}
] }]root attribute Is the name of the subcontracting folder ,pages Array , Place subcontracting pages , The rest and pages The page configuration of the folder is consistent
uni-app The routing Wechat applets are the same except for different prefixes
Tag jump
Tag name
<navigator url="/pages/home/home" open-type="navigate"></navigator>open-type Parameters
navigate | Will hide the current page Go to the new page Page stack up to ten layers |
redirect | Will destroy ( close ) Current page Go to the new page |
switchTab | Specifically for jump tabbar page He will destroy all non - tabbar page |
navigateBack | close Current page , Return to the previous level or multiple levels |
reLaunch | Jump tabbar page , Will close all pages Go to the new page |
Logic jump
| Keep the current page , Jump to a page in the app | |
| Close current page , Jump to a page in the app | |
| Close all pages , Open to a page in the app . | |
| Jump to tabBar page , And shut down all the others tabBar page | |
Close current page , Go back to the previous page or multi-level page It can be done by | |
| Preload the page , It's a performance optimization technology |
Routing parameters and receiving parameters
Be careful :switchTab Can't pass parameters
The ginseng :wx.redirectTo({ url: '/pages/home/home?id='+id })
receive : Loaded on the listening page onLoad Function parameter options Object
边栏推荐
- CSRF attack
- 有关计网的五种类型题
- Comparison and evaluation of digicert and globalsign single domain ov SSL certificates
- 戴尔科技演绎“快”字诀,玩转CI/CD
- [file inclusion vulnerability-04] classic interview question: how to getshell when a website is known to have only local file inclusion vulnerability?
- Network remote access using raspberry pie
- 单片机开发---基于ESP32-CAM的人脸识别应用
- NETCORE performance troubleshooting
- VW VH adaptation of mobile terminal
- 浅谈二叉树
猜你喜欢
![[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world](/img/f7/b3239802d19d00f760bb3174649a89.jpg)
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world

A five-year technical Er, based on the real experience of these years, gives some suggestions to the fresh students

Dell technology performs the "fast" formula and plays ci/cd

CSRF attack

Network remote access using raspberry pie

网络协议学习---LLDP协议学习

zabbix分布式系统监控

Houdini graphic notes: could not create OpenCL device of type (houdini_ocl_devicetype) problem solving

中國信通院沈瀅:字體開源協議——OFL V1.1介紹及合規要點分析
![[file containing vulnerability-03] six ways to exploit file containing vulnerabilities](/img/4f/495c852eb0e634c58e576d911a2c14.png)
[file containing vulnerability-03] six ways to exploit file containing vulnerabilities
随机推荐
Multiple environment variables
Is it safe to open a securities account in changtou school by mobile phone?
Garbage collection mechanism
Google Earth Engine(GEE)——evaluate实现一键批量下载研究区内的所有单张影像(上海市部分区域)
Floating window --- create a system floating window (can be dragged)
Dell technology performs the "fast" formula and plays ci/cd
持续交付-Jenkinsfile 语法
浅谈二叉树
Flutter adds event listening | subscription
Is it safe to open an account through mobile phone if you open an account through stock speculation? Who knows?
Google Earth engine (GEE) - evaluate enables one click batch download of all single images in the research area (some areas in Shanghai)
Flask blog practice - realize the latest articles and search in the sidebar
指南针在上面开股票账户安全吗?
VW VH adaptation of mobile terminal
性能之内存篇
keep-alive
撸一个随机数生成器
keep-alive
Handling of NPM I installation problems
单片机开发---基于ESP32-CAM的人脸识别应用