小程序開發(fā)筆記

微信小程序

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;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 134,981評(píng)論 19 139
  • 我是做iOS開發(fā)的,很多人都會(huì)說(shuō)這個(gè)微信小程序又是動(dòng)態(tài)的,我不反對(duì)蘋果對(duì)動(dòng)態(tài)的討厭,畢竟這樣很容易不受控制,但是R...
    DSperson閱讀 4,113評(píng)論 4 3
  • 本篇文章適合有一定編程基礎(chǔ)、剛接觸微信小程序的興趣愛(ài)好者閱讀。如果您是前端工程師可以直接去看微信小程序的接...
    HaiNiu0閱讀 1,009評(píng)論 0 0
  • 上一篇在介紹微信小程序的基礎(chǔ)的時(shí)候,其實(shí)已經(jīng)或多或少的談到了一些坑了,此篇文章會(huì)詳細(xì)羅列出在開發(fā)過(guò)程中遇到...
    HaiNiu0閱讀 1,080評(píng)論 0 1
  • BUG LIST this.setData is not a function reason:在網(wǎng)絡(luò)回調(diào)之后直接對(duì)...
    smallstrong閱讀 347評(píng)論 0 1