当前位置:网站首页>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 ,

边栏推荐
- Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
- MongoDB簡介
- Mysql Mac版下载安装教程
- Node start server
- Ansible introduction [unfinished (semi-finished products)]
- Introduction à mongodb
- [MySQL] the difference between left join, right join and join
- Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
- PHP generates PDF tcpdf
- PAT乙级“1104 天长地久”DFS优化思路
猜你喜欢

Nce detail of softmax approximation

Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11

LVGL使用心得

递归:深度优先搜索

Hi3536C V100R001C02SPC040 交叉编译器安装
![[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)](/img/19/815e7cba81f6eb52db5ef0db556dfd.jpg)
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)

MongoDB复制集【主从复制】

Introduction à mongodb

ffmpeg之 一张/多张图片合成视频

Table structure of Navicat export database
随机推荐
shardingsphere动态数据源
2020-01-01t00:00:00.000000z date format conversion
js中#号的作用
PAT乙级常用函数用法总结
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
900W+ 数据,从 17s 到 300ms,如何操作
Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
Pat class B "1104 forever" DFS optimization idea
Basic operations of mongodb [add, delete, modify, query]
Applet (continuous update)
npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
MySQL MAC download and installation tutorial
node,npm以及yarn下载安装
New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
Mongodb master profile
Hi3536C V100R001C02SPC040 交叉编译器安装
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!