当前位置:网站首页>Wechat applet - basic content
Wechat applet - basic content
2022-07-03 12:07:00 【Dull Yanan】
stay app.json Of page You can add directories directly in - File structure new , There is no need to use a suffix
window Fields are global style controls
Tabbar Usage of : Navigation bar usage at the bottom
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",
"text": " home page ",
"iconPath": "icon/_home.png",
"selectedIconPath": "icon/home.png"
},
{
"pagePath": "pages/img/img",
"text": " picture ",
"iconPath": "icon/_img.png",
"selectedIconPath": "icon/img.png"
},
{
"pagePath": "pages/mine/mine",
"text": " my ",
"iconPath": "icon/_my.png",
"selectedIconPath": "icon/my.png"
},
{
"pagePath": "pages/search/search",
"text": " Search for ",
"iconPath": "icon/_search.png",
"selectedIconPath": "icon/search.png"
}
],
"color": "#0094ff",
"selectedColor": "#ff9400"
},
color Is and list Of the same rank , stay 【 Then add , Set specific properties , You can go to the manual of the applet
Page configuration refers to individual json file , and app.json In the same way , Just read the document
stay wxml in
text amount to span label Inline elements Don't wrap
view amount to div label Blocky element I'll change lines
Data binding :
<!--pages/search/search.wxml-->
<text>pages/search/search.wxml</text>
<!-- character string -->
<view>{
{msg}}</view>
<!-- Numeric type -->
<view>{
{num}}</view>
<!-- object type -->
<view>{
{person.age}}</view>
<view>{
{person.height}}</view>
<view>{
{person.name}}</view>
<!-- String and {
{}} There must be no space between them -->
<!-- Radio buttons -->
<view>
<checkbox checked="{
{true}}"></checkbox>
</view>
// pages/search/search.js
Page({
/** * Initial data of the page */
data: {
msg:"Hello Msg",
num:"123",
person:
{
age:74,
height:135,
name:" Sunyanan "
}
},
The list of rendering
wx:for Circulation system
list:[
{
id:0,
name:" Pig eight quit "
},
{
id:1,
name:"www"
},
{
id:2,
name:"sssss"
},
]
<!-- List loop wx:for="{
{ Array or object }}" wx:for-item=" The name of the loop " wx:for-index=" Index of the loop item " wx:key=" The only value " Improve rendering speed wx:key="*this" Represents a cyclic term 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 . When using array loops Do not duplicate the binding name wx:for-item="item" wx:for-index="index" wx:key="id" By default, there is no need to write wx:for-item="item" wx:for-index="index" The subscript variable name of the current item in the default array defaults to index, The variable name of the current item of the array defaults to item -->
<view>
<view wx:for="{
{list}}" wx:for-item="item" wx:for-index="index" wx:key="id">
Indexes :{
{index}}
value :{
{item.name}}
</view>
<view wx:for="{
{list}}">
{
{index}}++++{
{item.name}}
</view>
</view>
Conditions apply colours to a drawing
<!-- Conditions apply colours to a drawing -->
<view>
<view> Conditions apply colours to a drawing </view>
<view wx:if="{
{true}}">Show</view>
<view hidden="{
{false}}"> This is hidden</view>
<!-- false Don't hide -->
</view>
Event binding
<!-- Event binding -->
<text>pages/demo1/demo1.wxml</text>
<!-- input The format of the problem final / -->\
<!-- Need to give input Tag binding input event Binding keywords bindinput="js Method name in " -->
<input type="text" bindinput="andleInput" />
<view>{
{num}}</view>
<!-- Get the value of the input box Get from the event source object e.detail.value Put the value of the input box Assign values to the data in Not directly this.data.num=e.detail.value this.num=e.detail.value The right way : this.setData({ num:e.detail.valued }) -->
andleInput(e)
{
console.log("Happy");
console.log(e);
this.setData({
num:e.detail.value
})
},
Event binding 2
num2 Need to be js Interface setting initial value
Page({
/** * Initial data of the page */
data: {
num2:0
},
addInput(e)
{
console.log(e);
// Get custom properties If you don't know what's going on e Print out Look at the data
const operation=e.currentTarget.dataset.operation;
console.log(operation);
this.setData({
//this.data It refers to the front data Under the this
num2:this.data.num2+=operation
})
},
<button bindtap="addInput" data-operation="{
{1}}">+</button>
<button bindtap="addInput" data-operation="{
{-1}}">-</button>
<view>{
{num}}</view>
<view>{
{num2}}</view>
Style import :
Use @import Statement can import an external stylesheet ,@import Followed by the relative path of the external stylesheet to be imported , use ; End of statement .
The pictures of wechat applet only support network pictures , Then a local image will exceed the size limit
Shuffling figure
Jump function
rich-text Rich text editor Direct analytical html
Get cell phone number
icon
radio Radio buttons
data: {
number: ""
},
handlechange(e)
{
console.log(e);
const n =e.detail.value;
console.log(n);
this.setData({
number:this.data.number=n
})
},
<view>
<radio-group bindchange="handlechange">
<radio value="1">111</radio>
<radio value="2">222</radio>
<radio value="3">333</radio>
<radio value="4">444</radio>
</radio-group>
</view>
<view> You have selected {
{number}}</view>
checkbox
Custom components
First, create a name called Components Folder Automatically build custom components and then create your own component folder Select build components
Go to the official documents I didn't learn this
The life cycle of the application
app.js Something in
// app.js
App({
onLaunch() {
// Page Jump s
// wx.navigateTo({
// url: '/12313/12313',
// })
// Demonstrate local storage capabilities Get the user's information
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// Sign in
wx.login({
success: res => {
// send out res.code Go backstage to exchange openId, sessionKey, unionId
}
})
},
// Seen by users
onShow()
{
console.log("show");
},
// Hidden by users
onHide()
{
console.log("hide");
},
// Application error
onError()
{
console,log(" Report errors ");
},
// If the entry page cannot be found, it will trigger
onPageNotFound()
{
console.log(" Page not found ");
},
globalData: {
userInfo: null
}
})
The life cycle of a page
It's the page js A pile of things It's no use
App.js Allow drop-down refresh
边栏推荐
- 为什么我的mysql容器启动不了呢
- 2022年湖南工学院ACM集训第二次周测题解
- ArcGIS应用(二十一)Arcmap删除图层指定要素的方法
- Interview experience in summer camp of Central South University in 2022
- Sheet1$. Output [excel source output] Error in column [xxx]. The returned column status is: "the text is truncated, or one or more characters have no matches in the target code page.".
- QT OpenGL rotate, pan, zoom
- Optimize interface performance
- 错排问题 (抽奖,发邮件)
- PHP导出word方法(一phpword)
- Qt OpenGL相机的使用
猜你喜欢
During FTP login, the error "530 login incorrect.login failed" is reported
vulnhub之momentum
vulnhub之presidential
ArcGIS application (XXI) ArcMap method of deleting layer specified features
Vulnhub geminiinc V2
[MySQL special] read lock and write lock
OpenGL draws colored triangles
Vulnhub narak
Ripper of vulnhub
Is BigDecimal safe to calculate the amount? Look at these five pits~~
随机推荐
Notes on 32-96 questions of sword finger offer
vulnhub之Nagini
Flutter: about monitoring on flutter applications
SLF4J 日志门面
[MySQL special] read lock and write lock
Introduction to the implementation principle of rxjs observable filter operator
laravel 时区问题timezone
(construction notes) learn the specific technology of how to design reusable software entities from three levels: class, API and framework
VS2015的下载地址和安装教程
Vulnhub's cereal
Unicode encoding table download
Download address and installation tutorial of vs2015
(construction notes) ADT and OOP
Quantitative calculation research
【mysql专项】读锁和写锁
Vulnhub narak
ArcGIS application (XXI) ArcMap method of deleting layer specified features
Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
vulnhub之cereal
(構造筆記)從類、API、框架三個層面學習如何設計可複用軟件實體的具體技術