微信小程序基础语法
<!--pages/home/home.wxml-->
<view>{{info}}</view>
<!-- 动态属性 不用加分号 -->
<image src="{{imgSrc}}" mode="widthFix"></image>
<view>生成100以内的随机数{{randomNum2 * 100}}</view>
<view>{{randomNum1 >= 5 ? "生成大于等于5的数字" : "生成小于5的数字"}}</view>
<button bindtap="bindTapHandler">
点击触发
</button>
<button bindtap="change">+1</button>
<button bindtap="changeInfo" data-info="{{2}}">+2</button>
<input bindinput="valueX"></input>
<view wx:if="{{type === 1}}">男</view>
<view wx:elif='{{type === 2}}'>女</view>
<view wx:else>保密</view>
<!-- hidden 控制显示隐藏 相当于show 通过改变样式切换的 不是针对dom树来的 -->
<view hidden="{{!flag}}">true显示 false隐藏</view>
<!-- wx:if控制 会改变dom树 消耗大 创建元素和移动删除-->
<view wx:if="{{flag}}">hdjsj</view>
<view wx:for="{{arr1}}" wx:key="index">
{{index}} {{item}}
</view>
changeInfo(e){
this.setData({
count: this.data.count + e.target.dataset.info
})
},
valueX(e) {
// e.detail.value 输入框更新变化之后的值
console.log(e.detail.value);
},
bindTapHandler(e) {
console.log(e)
},
// 修改count值
change(){
// this.setData(dataobject) 里面是对象
this.setData({
count: this.data.count + 1
})
},
info: 'hello word',
imgSrc: 'http://www.itheima.com/images/logo.png',
randomNum1: Math.random() * 10, //生成10已内的数字
randomNum2: Math.random().toFixed(2), // 生成2位随机小数
count: 0,
type: 0,
flag: true,
arr1: ['评估', '山东', '地方']
fn1() {
wx.request({
url: 'https://www.escook.cn/api/get',
data: {
name: '沾上干',
age: '20'
},
success (res) {
console.log(res.data)
}
})
},
状态响应问题:
错误写法:
success(res) {
.......
}
正确写法:
success: (res) => {
this.setData({
数组:res.data
})
}