5c96997f5c6150c61e157a7d2b4422b7 wx60d2bb1f9f2abb5d
mini app demo
一个span,两个按钮,点击按钮会让span加1或者减1。它简单到你不需要分心关注,但是由足够说明典型的html场景——就是既有数据呈现也有按钮操作。
UI看起来是这样的:
+
0
-
最低需要的5个文件的内容
app.json
index/index.wxml
index/index.wxss
index/index.js
index/index.json
{
"pages": [
"pages/index/index"
]
}
<view class="container">
<button bindtap="inc">+</button>
<text>{{count}}</text>
<button bindtap="dec">-</button>
</view>
.container{
display: flex;
flex-direction: row;
justify-content: flex-start;
}
Page({
data: {
count:0,
},
inc: function (e) {
this.setData({ count: this.data.count+1})
},
dec: function (e) {
this.setData({count:this.data.count-1})
}
})
{
"usingComponents": {}
}
定义于 app.js 内的数据
App({
globalData: {
userInfo: null
}
})
使用数据页面
const app = getApp()
app.globalData.userInfo // 可读可写
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
wx.navigateTo({
url: '../detail/detail?type=3',
})
Page({
onLoad: function (options) {
this.setData({ type: +options.type-1})
},
})