![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921092205423-1646463912.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921092802264-1707554316.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921092906157-662606609.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921092937058-163407399.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094502031-2010057544.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094538874-637712165.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094611644-1696402414.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094625628-1760334308.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094658897-1894131689.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094710569-1322871569.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094812467-757758565.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094821124-1589043225.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094834055-274890281.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094857669-558608531.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094912200-2107989848.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094932491-1620441986.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921094950942-184668488.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095017115-1964795044.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095040483-716233907.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095621098-1990611361.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095640792-499979529.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095711281-1840131210.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095732246-382702242.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095755331-1694902846.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095833616-886036806.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095904434-2073800457.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921095930006-1373454216.png)
<!--pages/home/home.wxml-->
<!-- 1.小程序的数据绑定: {{}} -> Mustache -->
<view>Hello {{name}}</view>
<view>我的年龄: {{age}}</view>
<!-- 2.列表展示: wx:for -->
<view wx:for="{{students}}">{{item.name}}-{{item.age}}</view>
<!-- 3.事件监听改变data -->
<view>当前计数: {{counter}}</view>
<button size='mini' bindtap='handleBtnClick'>+</button>
<button size='mini' bindtap='handleSubtraction'>-</button>
Page({
data: {
name: 'Coderwhy',
age: 18,
students: [
{id: 110, name: 'kobe', age: 30},
{id: 111, name: 'james', age: 28},
{id: 112, name: 'curry', age: 32},
{id: 113, name: 'why', age: 18}
],
counter: 0
},
handleBtnClick() {
// 1.错误做法: 界面是不会刷新的
// this.data.counter += 1
// console.log(this.data.counter)
// 2.this.setData()
this.setData({
// 支持 +1 和 +=1 这两种写法,不支持 ++
counter: this.data.counter + 1
})
},
handleSubtraction() {
this.setData({
counter: this.data.counter - 1
})
}
})
// 编程范式:
// 1.命令式编程: 原生操作DOM
// 2.声明式编程: Vue/React/Angular
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921103128967-1678927927.png)
![](https://img2020.cnblogs.com/blog/1877004/202009/1877004-20200921103141909-486963092.png)