1. 小程序中如何携带cookie?
在登录请求后读取 返回值的, header的cookie,并本地存储
wx.setStorageSync("sessionid", res.header["Set-Cookie"])
在下一次请求的时候设置header,并写入cookie
header = {
'content-type': 'application/x-www-form-urlencoded',
'cookie':"SESSID=" + wx.getStorageSync("sessionid")
};
2.小程序中如何定义事件?如何传递参数?如何取到参数?
wxml:
<view bindtap="goTo" data-index={{item.index}}>点击事件传参</view>
js中:
goTo: function(e){
// 传递的参数
const index= e.currentTarget.dataset['index'];
}
3.如何阻止事件冒泡?如何设置事件在捕获阶段触发?
<!-- 阻止事件冒泡 -->
<!-- 事件冒泡是从外往里触发 -->
<view class="box" bind:tap="log1">
<!-- 当你把bind 换成 catch 就不会触发冒泡事件 -->
<!-- <button bind:tap="log2">按钮2</button> -->
<button catch:tap="log2">按钮2</button>
</view>
<!-- 捕获事件 -->
<view class="box" bind:tap="log1">
<!-- 当你把bind 换成 capture-bind 就可以触发捕获事件 -->
<!-- <button bind:tap="log2">按钮2</button> -->
<button capture-bind:tap="log2">按钮2</button>
</view>