2020.9.28陈悦玲
1.跳转页面
//点击跳转按钮的时候,调用方法turnto
//bintap cacthtap
//使用redirectTo方法跳转到demo1的页面
turn1:function(){
wx.redirectTo({
url: '../demo2/demo2?twotothree'+this.data.twotothree,
})
},//只跳转
//跳转加传值
wx.redirectTo({
url:"../demo1/demo1?tiaozhuan"+this.data.tiaozhuan+'&other=传第二个值就用&符'
})
2.事件处理函数
3.自定义事件绑定
<view catchtap="show">我是不冒泡</view>
<view catchtap="maopao">
<view bindtap="maopao2">
我是冒泡(冒泡就是从上面的能点到下面的)
</view>
</view>
//js
show(){
wx.showToast({
title: '成功',
icon:"loading",
duration:1000,
})
},
maopao(){
console.log("我是冒泡哦")
},
4.循环
<!-- 循环 -->
<view wx:for="{{student}}" wx:key="{{key}}">
<view>{{item}}</view>
</view>
<!-- 循环变量(一般就是 数组+对象) -->
<!-- wx:for="{{我们要循环的数组}}"
item 表示我们循环的每一项
-->
<view wx:for="{{student2}}" wx:key="{{index}}">
<view>{{item}}</view>
</view>
//js
data: {
student:[1,2,3,4,6,6,7,8,9,10],
index:0,
student2:{
name:"陈小玲玲",
age:20,
sex:"女"
}
},
5.调用接口并且返回接口中的值
<button catchtap="videoshow">didi</button>
<!-- <text>{{moviename}}</text> -->
<view wx:for="{{results}}">
<view>{{item.title}}</view>
</view>
//js
data: {
results:""
},
videoshow(){
var that=this;//固定指针,现在的this指向page,给that就行
wx.request({
url:"http://api.douban.com/v2/movie/new_movies?apikey=0df993c66c0c636e29ecbb5344252a4a",
method:"get",
header:{
'content-type':'application/x-www-form-urlencoded'
},
success(res){//也可以写success:function(res){}
// console.log(res);
//res是请求的服务器的数据!!!!!!!!!!!!!!!!!!!!!!
// 把请求到的数据保存到页面中的movie中,显示到页面中
// 数据绑定用
// console.log(res.data.subjects)
// 数据绑定
//如果我们想要使用data中的数据,就必须请求接口
//避免反复的请求接口,我们就要找一个新的变量来保存我们返回的数据,所以上面的data会有一个空的results:""
that.setData({
results:res.data.subjects
})
//这里是更改我们data中的值
}
})
},
// 请求接口:
// 1.在测试阶段,可以在详情中打开不检验https
// 2.在公众平台配置域名
// 3.其实类似于ajax的存在
//
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// this.setData({
// moviename:options.subjects.title
// })
},
6.if
<view wx:if="{{item.rating.average>6}}">{{item.rating.average}}</view>
<!-- if里面的语句只有为true才会正常显示 -->
<!--if-elif-else -->
7.hidden
<view hidden="{{sex==0}}">开心超人</view>
<!-- hidden="{{condition}}" 当condition为true时就隐藏,为false就显示,一般不用if-else 用hidden更好-->
近期评论