亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序?qū)崿F(xiàn)頁(yè)面跳轉(zhuǎn)傳值以及獲取值的方法分析

 更新時(shí)間:2017年12月18日 10:28:36   作者:jia635  
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)頁(yè)面跳轉(zhuǎn)傳值以及獲取值的方法,結(jié)合實(shí)例形式總結(jié)分析了微信小程序頁(yè)面跳轉(zhuǎn)及傳值的常用操作技巧,需要的朋友可以參考下

本文實(shí)例講述了微信小程序?qū)崿F(xiàn)頁(yè)面跳轉(zhuǎn)傳值以及獲取值的方法。分享給大家供大家參考,具體如下:

在安卓中頁(yè)面跳轉(zhuǎn)傳值都是通過(guò)bundle,現(xiàn)在研究一下小程序的列表跳轉(zhuǎn)及頁(yè)面?zhèn)髦怠?/p>

my.wxml

<view class="container">
 <view bindtap="bindViewTap" class="userinfo">
  <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
  <text class="userinfo-nickname">{{userInfo.nickName}}</text>
 </view>
 <view class="info_list">
  <block wx:for="{{userListInfo}}" >
   <view class="weui_cell" data-index="{{item.index}}" id="{{item.index}}"
    bindtap="userinfo_item">
    <view class="weui_cell_hd">
     <image src="{{item.icon}}"></image>
    </view>
    <view class="weui_cell_bd">
     <view class="weui_cell_bd_p"> {{item.text}} </view>
    </view>
    <view wx:if="{{item.isunread}}" class="badge">{{item.unreadNum}}</view>
    <view class="with_arrow"></view>
   </view>
  </block>
 </view>
</view>

my.js

var app = getApp()
Page({
 data: {
  userInfo: {},
  userListInfo: [{
   icon: '../../images/iconfont-dingdan.png',
   text: '我的訂單',
   isunread: true,
   unreadNum: 2,
   index:1
  }, {
   icon: '../../images/iconfont-kefu.png',
   text: '聯(lián)系客服',
   index: 5
  }, {
   icon: '../../images/iconfont-help.png',
   text: '常見(jiàn)問(wèn)題',
   index: 6
  }]
 },
 onLoad: function () {
  var that = this
  //調(diào)用應(yīng)用實(shí)例的方法獲取全局?jǐn)?shù)據(jù)
  app.getUserInfo(function (userInfo) {
   //更新數(shù)據(jù)
   that.setData({
    userInfo: userInfo
   })
  })
 },
 userinfo_item: function (e) {
  var index = e.target.dataset.index;
  console.log("----index----" + index)
  console.log('-----id-----'
   + e.currentTarget.id)
  var app = getApp();
  //設(shè)置全局的請(qǐng)求訪問(wèn)傳遞的參數(shù)
  app.requestId = e.currentTarget.id;
  app.requestIndex = index;
 }
})

微信小程序設(shè)置id的方法標(biāo)識(shí)來(lái)傳值

在要跳轉(zhuǎn)的item處,設(shè)置一個(gè)id并給當(dāng)前的id賦值上對(duì)應(yīng)的key值,
id="{{item.index}}"
后我們?cè)趈s的bindtap的響應(yīng)事件中獲取,并傳遞到下一個(gè)界面中;
獲取到id傳的值
通過(guò)e.currentTarget.id;獲取設(shè)置的id值,并通過(guò)設(shè)置全局對(duì)象的方式來(lái)傳遞數(shù)值,
獲取全局對(duì)象 var app=getApp(); //設(shè)置全局的請(qǐng)求訪問(wèn)傳遞的參數(shù) app.requestDetailid=id;
在調(diào)試模式下:我們也可以在,wxml中查看到我們?cè)O(shè)置的每一個(gè)item的id值

通過(guò)使用data - xxxx 的方法標(biāo)識(shí)來(lái)傳值

通過(guò)使用data - xxxx 的方法標(biāo)識(shí)來(lái)傳值,xxxx可以自定義取名 比my.wxml中的data-index。
如何獲取data-xxxx傳遞的值?
在js的bindtap的響應(yīng)事件中:
通過(guò)數(shù)據(jù)解析一層層找到數(shù)據(jù),var id=e.target.dataset.index(根據(jù)你的data-id的取名)
如js中的兩個(gè)打印就是通過(guò)兩種不同方式獲得的id。

微信小程序如何跨頁(yè)面獲取值

依據(jù)上面的方式設(shè)置要傳遞的值,頁(yè)面跳轉(zhuǎn)后,我們就需要在下一個(gè)頁(yè)面拿到傳遞的數(shù)據(jù)(這個(gè)數(shù)據(jù)在傳遞前,就已經(jīng)被設(shè)置成全局變量)相當(dāng)于給全局變量添加了新的key,value
在跳轉(zhuǎn)后的js頁(yè)面,接收傳遞過(guò)來(lái)的數(shù)據(jù)detail.js
同樣通過(guò)全局額方式取值出來(lái),(即和app.js中取某個(gè)變量的值是一樣的)

var id=getApp().requestId;
var index=getApp().requestIndex;
console.log(id);
console.log(index);

通過(guò)鏈接傳參:

wx.navigateTo({
 url: '/pages/account/feedback/feedback?test=feedback_test&name=jia',
 success: function(res) {},
 fail: function(res) {},
 complete: function(res) {},
})

點(diǎn)擊頁(yè)面跳轉(zhuǎn)時(shí)通過(guò)?方式傳參。在跳轉(zhuǎn)后的頁(yè)面JS中做如下接收:

onLoad: function (e) {
  var movieid = getApp().requestId;
  var movieIndex = getApp().requestIndex;
  console.log("-----feedback--movieid--" + movieid +" " + movieIndex);
  console.log("-----feedback--test--" + e.test);
  console.log("-----feedback--name--" + e.name);
 },

感覺(jué)比較好的方法還是通過(guò)鏈接方式進(jìn)行參數(shù)傳遞,第一種有些像安卓中進(jìn)行頁(yè)面跳轉(zhuǎn),把一些傳遞的參數(shù)寫(xiě)到Application中,第二種是像通過(guò)bundle方式進(jìn)行傳遞。前端小白總結(jié),希望前端豐富的同學(xué)可以提供更多思路。

希望本文所述對(duì)大家微信小程序開(kāi)發(fā)有所幫助。

相關(guān)文章

最新評(píng)論