微信小程序
1、taBar不顯示
tabBar的注冊(cè)是在app.json中,list中pagePath的值要按pages中注冊(cè)的路徑得順序賦值
2、for循環(huán)
循環(huán)的時(shí)候,數(shù)組遍歷的不能是對(duì)象
<block wx:for="{{數(shù)組}}" ></block>
循環(huán)的時(shí)候,數(shù)組遍歷的是對(duì)象
<block wx:for="{{數(shù)組}}" wx:for-item="value" wx:key="*this">
<text class="log-item">{{index + 1}}. {{value}}</text>
</block>
3、navigatorTo:fail url not in app.json
這是導(dǎo)航頁(yè)面跳轉(zhuǎn)出現(xiàn)的錯(cuò)誤,主要原因是沒(méi)有在app.json內(nèi)注冊(cè)該跳轉(zhuǎn)的路徑。
navigator 導(dǎo)航導(dǎo)航分三種
open-type="navigate" 打開新界面
open-type="redirect" 在本界面中打開新界面
open-type="switchTab" 控制tab頁(yè)之間的切換,只能打開tabBar注冊(cè)的界面
4、scroll-view
使用豎向滾動(dòng)時(shí),需要給<scroll-view/>一個(gè)固定高度。
還要給<scroll-view/>填充內(nèi)容才會(huì)執(zhí)行l(wèi)oadMore,refresh。
<scroll-view style="height:100vh;" scroll-y="true" bindscrolltolower="loadMore" bindscrolltoupper="refresh">
</scroll-view>
5、頁(yè)面?zhèn)鲄?/h3>
傳遞字符串
Page({
data: {
testStr: '字符串'
},
onLoad: function () {
},
next: function(e){
wx.navigateTo({
url: '/pages/test/test?str='+this.data.testStr,
})
}
})
接收字符串
Page({
data:{
},
onLoad:function(options){
console.log("接收到的參數(shù)是str="+options.str);
}
})
傳遞對(duì)象
Page({
data: {
testData:{name:'我是name', extra:'我是extra'}
},
onLoad: function () {
},
next: function(e){
wx.navigateTo({
url: '/pages/test/test?extra='+JSON.stringify(this.data.testData)
})
}
})
接收對(duì)象
Page({
data:{
testData:null
},
onLoad:function(options){
console.log("接收到的參數(shù)是obj="+options.extra);
this.dat.testData = JSON.parse(options.extra);
}
})
傳遞list
Page({
data: {
list:['item-A','item-B']
},
onLoad: function () {
},
next: function(e){
wx.navigateTo({
url: '/pages/test/test?list='+JSON.stringify(this.data.list),
})
}
})
接收l(shuí)ist
<span style="font-size:14px;">Page({
data:{
list:[]
},
onLoad:function(options){
console.log("接收到的參數(shù)是list="+options.list);
this.data.list = JSON.parse(options.list);
}
})
6、點(diǎn)擊事件傳參
通過(guò)wxml設(shè)置data-[參數(shù)名]傳遞參數(shù),[參數(shù)名]只能是小寫,不能有大寫
<view bindtap="clickMe" data-albumlist={{testData.albumList}}">
...
</view>
接收點(diǎn)擊參數(shù)
Page({
clickMe: function(event) {
var albumList = event.currentTarget.dataset.albumlist.split(",");
wx.navigateTo({
url: '../../pages/test/test'
})
}
})
7、獲取form表單的值
通過(guò)bindinput獲取input值
wxml頁(yè)面:
<view class="section">
<view class="section__title">你輸入的是:{{inputValue}}</view>
<input bindinput="bindKeyInput" placeholder="輸入同步到view中"/>
</view>
js頁(yè)面
bindKeyInput: function(e) {
this.setData({
inputValue: e.detail.value
})
}
通過(guò)bindvubmit獲取input值
wxml頁(yè)面:
<form bindsubmit="formSubmit">
<input name="detail" placeholder="詳情地址" />
<input name="realname" placeholder="收件人姓名" />
<input name="mobile" placeholder="手機(jī)號(hào)碼" type="number"/>
<button formType="submit" type="primary">Submit</button>
</form>
js頁(yè)面
formSubmit: function(e) {
var detail = e.detail.value.detail;
var realname = e.detail.value.realname;
var mobile = e.detail.value.mobile;
}