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