当前位置:网站首页>Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information
Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information
2022-07-03 03:34:00 【Water W】
Catalog
One 、 Global configuration app.json
3、 ... and 、 Get user information
Four 、 Get user location information
One 、 Global configuration app.json
{
"pages":[
"pages/home/home",
"pages/message/message",
"pages/contact/contact",
"pages/list/list"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#2b4b6b",
"navigationBarTitleText": " Local life ",
"navigationBarTextStyle":"white",
"backgroundColor": "#efefef",
"onReachBottomDistance": 50
},
"tabBar": {
"selectedColor": "#C00000",
"list": [
{
"pagePath": "pages/home/home",
"text": " home page ",
"iconPath": "/images/tabs/home.png",
"selectedIconPath": "/images/tabs/home-active.png"
},
{
"pagePath": "pages/message/message",
"text": " news ",
"iconPath": "/images/tabs/message.png",
"selectedIconPath": "/images/tabs/message-active.png"
},
{
"pagePath": "pages/contact/contact",
"text": " Contact us ",
"iconPath": "/images/tabs/contact.png",
"selectedIconPath": "/images/tabs/contact-active.png"
}
]
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
Two 、 Data binding
2.1 To write home page
(1)home.wxml
<!--pages/home/home.wxml-->
<view class="menu">
<view class="item">
<image src="/static/link-01.png"></image>
<text> The high-quality goods </text>
</view>
<view class="item">
<image src="/static/link-01.png"></image>
<text> The high-quality goods </text>
</view>
<view class="item">
<image src="/static/link-01.png"></image>
<text> The high-quality goods </text>
</view>
<view class="item">
<image src="/static/link-01.png"></image>
<text> The high-quality goods </text>
</view>
</view>
<navigator url="/pages/list/list?id=566"> Jump to the page </navigator>
(2)home.wxss
/* pages/home/home.wxss */
image {
width: 100rpx;
height: 100rpx;
border-radius: 50rpx;
}
.menu {
display: flex;
/* Arrange horizontally , Specify the spindle direction */
flex-direction: row;
/* How elements are displayed horizontally , Specify how to display in the spindle direction :center */
justify-content: space-around;
}
.menu .item {
display: flex;
flex-direction: column;
align-items: center;
}
2.2 To write list page
(1)list.wxml
<!--pages/list/list.wxml-->
<!-- Rotation chart structure -->
<swiper class="swiper-container" indicator-dots indicator-color="white" indicator-active-color="black" autoplay interval="3000" circular>
<swiper-item><view class="item">A</view></swiper-item>
<swiper-item><view class="item">B</view></swiper-item>
<swiper-item><view class="item">C</view></swiper-item>
</swiper>
<!-- Scroll view structure -->
<scroll-view class="container1" scroll-y>
<view>A</view>
<view>B</view>
<view>C</view>
</scroll-view>
<!-- Data binding -->
<view> data :{
{ message }}</view>
<button bindtap="checkData"> Click modify data </button>
(2)list.js
// pages/list/list.js
Page({
/**
* Initial data of the page
*/
data: {
message: "Sd"
},
checkData() {
// Modifying data
this.setData({message: "ssdss"})
},
/**
* Life cycle function -- Monitor page loading
*/
onLoad(options) {
},
/**
* Life cycle function -- Listening page first rendering completed
*/
onReady() {
console.log(this.options)
},
/**
* Life cycle function -- Monitor page display
*/
onShow() {
},
/**
* Life cycle function -- Monitor page hidden
*/
onHide() {
},
/**
* Life cycle function -- Monitor page uninstall
*/
onUnload() {
},
/**
* Page related event handler -- Monitor user pull-down action
*/
onPullDownRefresh() {
},
/**
* Handling function of page pull bottom event
*/
onReachBottom() {
},
/**
* Users click the upper right corner to share
*/
onShareAppMessage() {
}
})
(3)list.json It hasn't changed
2.3 Show the effect :
(1)home The display effect of the page is :
(2) Click on home On the page “ Jump to the page ” , You can jump to list page ,list The display effect of the page is :
(3) Click on list On the page “ Click modify data ” Button , You can put “ data :Sd” It is amended as follows “ data :ssdss”,
OK, The function of data binding is briefly introduced here .
3、 ... and 、 Get user information
Be careful : To get user information , Must be authorized by the user (button)
- Authorized
- unauthorized , By calling wx.opensetting({})
3.1 Mode one
To write list page
(1)list.wxml
<!--pages/list/list.wxml-->
<view> Current user name :{
{ name }}</view>
<ciew> Head portrait :<image src="{
{ path }}" style="height: 200rpx;width: 200rpx;"></image></ciew>
<button bindtap="getUserInfo"> Get username </button>
(2)list.js
// pages/list/list.js
getUserInfo() {
// Open configuration , Proceed to receive authorization
wx.openSetting({})
var that = this
// Get username
wx.getUserInfo({
success: function(res) {
console.log(res)
that.setData({
name: res.userInfo.nickName,
path: res.userInfo.avatarUrl})
},
fail:function(res) {
}
})
},
Show the effect :
(1) Click on home On the page “ Jump to the page ” , You can jump to list page ,list The display effect of the page is :
(2) Click on “ Get username ” Button , Then it is shown as follows ,
3.2 Mode two
To write list page
(1)list.wxml
<!--pages/list/list.wxml-->
<view> Current user name :{
{ name }}</view>
<ciew> Head portrait :<image src="{
{ path }}" style="height: 200rpx;width: 200rpx;"></image></ciew>
<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo"> pick up information </button>
(2)list.js
Be careful : In code “var that = this” Because it's directly in wx.getUserInfo Call in function this You can't get setData Of , So it must be here wx.getUserInfo External import of function this, Can only be .
// pages/list/list.js
bindGetUserInfo() {
// Open configuration , Proceed to receive authorization
wx.openSetting({})
var that = this
// Get username
wx.getUserInfo({
success: function(res) {
console.log(res)
that.setData({
name: res.userInfo.nickName,
path: res.userInfo.avatarUrl})
},
fail:function(res) {
}
})
},
Show the effect :
(1) Click on home On the page “ Jump to the page ” , You can jump to list page ,list The display effect of the page is :
(2) Click on “ Get username ” Button , Then it is shown as follows ,
(3) You can see it , The display effect is the same as that of mode 1 .
Four 、 Get user location information
To write list page
(1)pages/list/list.wxml
<!--pages/list/list.wxml-->
<view bindtap="getLocalPath">{
{ localPath }}</view>
(2)pages/list/list.js
// pages/list/list.js
getLocalPath() {
var that = this
// Get user location information
wx.chooseLocation({
success: function(res) {
console.log(res)
that.setData({localPath:res.address})
}
})
},
Show the effect :
(1) Click on home On the page “ Jump to the page ” , You can jump to list page ,list The display effect of the page is :
(2) Click on “ Please choose a location ”, Then it is shown as follows ,
边栏推荐
- [Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
- QT based tensorrt accelerated yolov5
- Vs 2019 installation and configuration opencv
- Ansible introduction [unfinished (semi-finished products)]
- @Accessors annotation function specifies that the prefix follows the hump naming
- PAT乙级常用函数用法总结
- redis在服务器linux下的启动的相关命令(安装和配置)
- 动态规划:最长回文子串和子序列
- [embedded module] OLED display module
- softmax的近似之NCE详解
猜你喜欢
Why does thread crash not cause JVM crash
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
Leetcode: dynamic planning template
[MySQL] the difference between left join, right join and join
Introduction to mongodb
渤、黄海的潮汐特征
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
Don't use the new Dede collection without the updated Dede plug-in
Tidal characteristics of the Bohai Sea and the Yellow Sea
The calculation of stripe, kernel and padding in CNN
随机推荐
VS克隆时显示403错误
2020-01-01t00:00:00.000000z date format conversion
Pat class B common function Usage Summary
ffmpeg录制屏幕和截屏
Pytorch multi card distributed training distributeddataparallel usage
Dynamic programming: longest common substring and longest common subsequence
Introduction à mongodb
MongoDB基本操作【增、删、改、查】
ffmpeg下载安装教程及介绍
MongoDB安装 & 部署
程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
[set theory] partial order relation (partial order relation definition | partial order set definition | greater than or equal to relation | less than or equal to relation | integer division relation |
[leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
[combinatorics] number of solutions of indefinite equations (number of combinations of multiple sets R | number of non negative integer solutions of indefinite equations | number of integer solutions
900w+ data, from 17s to 300ms, how to operate
VS 2019安装及配置opencv
Applet (continuous update)
Open Visual Studio 2010 hangs when opening a SQL file sql file
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)