国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

微信小程序 頁面跳轉(zhuǎn)傳參詳解

2019-11-20 08:38:12
字體:
供稿:網(wǎng)友

 微信小程序 頁面跳轉(zhuǎn)傳參,做微信小程序必定會用的這樣的功能,這里就記錄下本人學(xué)習(xí)實現(xiàn)代碼資料。

剛接觸微信小程序,多里面的語法和屬性還不怎么聊解,如有不多的地方希望各位大神多多指教。今天來說下微信小程序怎么跳轉(zhuǎn)和傳參,話不多說直接上代碼。

實現(xiàn)的功能是給列表增加點擊功能傳參到下一頁;

   

代碼如下:

<import src="../WXtemplate/headerTemplate.wxml"/> <view>  <!--滾動圖-->  <view>  <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoPlay}}" interval="{{intervalTime}}" duration="{{Time}}">  <block wx:for="{{imageURl}}">   <swiper-item>    <image src="{{item}}" class="imagePX"></image>   </swiper-item>  </block>  </swiper>  </view>  <!--功能按鈕-->  <view class="section-bg">  <block wx:for="{{buttonNum}}">   <!--模版-->   <template is="buttonList" data="{{item}}"/>   <!--<view class="section-item">   <image class="section-img" src="{{item.image}}"></image>   <text class="section-text">{{item.text}}</text>  </view>-->  </block>  </view>  <!--資訊列表-->  <view>  <block wx:for="{{listNum}}">   <template is="newList" data="{{item,index}}"/>  </block>    </view>    </view> 

其中

<template is="buttonList" data="{{item}}"/> 

為模版代碼如下

<template name="buttonList">  <view class="section-item">   <image class="section-img" src="{{item.image}}" bindtap="buttonClick"></image>   <text class="section-text">{{item.text}}</text>  </view> </template>  <!--list--> <template name="newList">  <view class="section-list" bindtap="listClick" id="{{index}}">  <view>   <image class="list-img" src="{{item.image}}"></image>  </view>    <view class="section-textt">   <view class="title"><text>{{item.title}}</text></view>   <view class="subTitle"><text>{{item.subTitle}}</text></view>  </view>  </view>  </template> 

這里只為下面的列表增加了點擊方法

點擊列表js代碼

listClick:function(event){  console.log(event);  var p = event.currentTarget.id   wx.navigateTo({url:'/pages/xiangqing/xiangqing?id=上一頁的參數(shù)'})  } 

其中

wx.navigateTo({url:'/pages/xiangqing/xiangqing?id=上一頁的參數(shù)'}) 

為跳轉(zhuǎn)方法,id為需要傳的參數(shù) 如果參數(shù)為動態(tài)參數(shù)代碼如下: 

listClick:function(event){  console.log(event);  var p = event.currentTarget.id   wx.navigateTo({url:'/pages/xiangqing/xiangqing?id='+p})  } 

其中p為上面為每一行設(shè)置的id值

在下一頁取值代碼如下: 

 data:{  // text:"這是一個頁面"  title:''  },  onLoad:function(options){  // 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)  this.setData({  title:options.id  }) 

然后在頁面上顯示代碼如下:

<view>{{title}}</view> 

最終實現(xiàn)效果:

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 江华| 沙河市| 集贤县| 长丰县| 新和县| 大安市| 阿鲁科尔沁旗| 松潘县| 新龙县| 湘西| 丰台区| 夹江县| 行唐县| 清原| 新巴尔虎左旗| 随州市| 丰原市| 芮城县| 长宁县| 信宜市| 青神县| 江都市| 滨海县| 洪雅县| 凤城市| 揭西县| 巴林右旗| 疏勒县| 兴和县| 宁南县| 前郭尔| 营口市| 宜黄县| 荥经县| 灵武市| 应用必备| 固原市| 湖口县| 乌兰察布市| 句容市| 旬阳县|