[小程序开发]页面间传递数据

2023年6月9日 09:58 by wst

小程序

微信的接口,从2.2.2基础版本开始,页面跳转增加了数据传递的方法。

原页面

功能:页面转发、超链接跳转

index.js文件:

const app = getApp()

Page({
  data: {

  },
  onShareAppMessage: function () {
    return {
      title: '自定义转发标题',
      path: '/index/index?id=123'
    }
  },
  onLoad: function () {
    console.log('代码片段是一种迷你、可分享的小程序或小游戏项目,可用于分享小程序和小游戏的开发经验、展示组件和 API 的使用、复现开发问题和 Bug 等。可点击以下链接查看代码片段的详细文档:')
    console.log('https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/devtools.html')
  },

  toNewPage(e){
    wx.navigateTo({
      url: '/new/new?query=111',
      events: {
        // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
        acceptDataFromOpenedPage: function(data) {
          console.log("return:", data)
        },
        someEvent: function(data) {
          console.log("return some:",data)
        }
      },
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'good' })
      }
    })
  },
  onShow: function() {
    console.log("index show")
  }
})

index.xml文件:

<view class="intro">欢迎使用代码片段,可在控制台查看代码片段的说明和文档</view>
<view class="intro">
  <navigator url="/new/new" class="nav">
    去新页面
  </navigator>
  <button bindtap="toNewPage" type="primary">按钮跳转</button>
</view>

index.wxss文件:

.intro {
  margin: 30px;
  text-align: center;
}

.nav{
  color: blue;
}

目标页面

new.js文件:

// new/new.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("query:", options.query)
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});
    eventChannel.emit('someEvent', {data: 'test'});
    // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('acceptDataFromOpenerPage', function(data) {
      console.log("aim page:", data)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

new.wxml文件:

<!--new/new.wxml-->
<view>跳转到的页码</view>

new.wxss文件:

view {
  margin: 30px;
  text-align: center;
}

总结

代码包含的主要功能为:

1. index.js页面可转发的设置

2. 通过超链接传递数据的方法:发送、接收、监听。

 


Comments(126) Add Your Comment

Pvrrqn
buy atorvastatin 80mg generic <a href="https://lipiws.top/">buy cheap generic atorvastatin</a> order atorvastatin 20mg generic
Kgxmjl
cipro drug - <a href="https://metroagyl.top/keflexcapsule/">order cephalexin 125mg online</a> order augmentin 625mg generic
Dlhwhh
purchase ciprofloxacin without prescription - <a href="https://cipropro.top/bactrimos/">buy bactrim 480mg pills</a> order amoxiclav generic
Jgowyh
order metronidazole 400mg - <a href="https://metroagyl.top/oxytetracycline/">order terramycin 250 mg without prescription</a> order zithromax 500mg sale
Zhrxen
ciplox 500 mg tablet - <a href="https://septrim.top/trimox/">amoxicillin pills</a> erythromycin price
Ggkoqk
valtrex 1000mg canada - <a href="https://gnantiviralp.com/starlix/">brand nateglinide</a> brand zovirax 400mg
Krufvx
ivermectin dosage - <a href="https://keflexin.top/aczone/">buy aczone cheap</a> where can i buy tetracycline
Awzpdh
flagyl order - <a href="https://metroagyl.top/oxytetracycline/">oxytetracycline capsules</a> order zithromax 250mg without prescription
Srozua
buy acillin generic <a href="https://ampiacil.top/amoxil500/">cheap amoxicillin generic</a> purchase amoxicillin without prescription
Zpkrgs
lasix 100mg pills - <a href="https://antipathogenc.com/medex/">order warfarin generic</a> oral captopril 25mg
Wnbzhi
buy glycomet pill - <a href="https://gnantiacidity.com/baycip/">cipro 1000mg usa</a> lincocin 500 mg without prescription
Irvfbz
pill zidovudine - <a href="https://canadiangnp.com/rulide/">order roxithromycin generic</a> order zyloprim 100mg generic
Vajges
oral clozaril 50mg - <a href="https://genonlinep.com/coversyl/">aceon for sale online</a> pepcid 40mg price
Dopbay
quetiapine order - <a href="https://gnkantdepres.com/bupron/">bupropion pill</a> buy eskalith pill
Vbufmn
buy generic atarax - <a href="https://antdepls.com/pamelor/">buy nortriptyline without a prescription</a> buy amitriptyline without prescription
Oskqeg
where to buy clomipramine without a prescription - <a href="https://antdeponline.com/paxil/">buy cheap paxil</a> doxepin where to buy
Wtztlx
amoxil uk - <a href="https://atbioxotc.com/">cheap amoxicillin tablets</a> buy baycip sale
Ugkobs
buy clavulanate medication - <a href="https://atbioinfo.com/septra/">order bactrim for sale</a> ciprofloxacin price
Umyrbo
cleocin 300mg price - <a href="https://cadbiot.com/doxycycline/">order acticlate pills</a> cheap chloramphenicol tablets
Mmtgbn
buy generic zithromax 250mg - <a href="https://gncatbp.com/emetronidazole/">flagyl 200mg sale</a> generic ciprofloxacin 500 mg
Yupwlc
purchase albuterol pills - <a href="https://antxallergic.com/xsseroflo/">purchase seroflo generic</a> theo-24 Cr 400 mg price
Ekhyip
stromectol coupon - <a href="https://antibpl.com/szdoryx/">doryx tablets</a> order cefaclor 500mg sale
Cbxexi
desloratadine order online - <a href="https://rxtallerg.com/getaristocort/">triamcinolone 4mg tablet</a> albuterol inhaler
Ozacow
medrol generic - <a href="https://ntallegpl.com/loratadine/">purchase claritin sale</a> cheap astelin
Ffyjtn
buy generic micronase for sale - <a href="https://prodeprpl.com/pioglitazone30/">brand actos 15mg</a> forxiga 10 mg price
Xnqokq
repaglinide 2mg us - <a href="https://depressinfo.com/">buy prandin 1mg online cheap</a> order jardiance 10mg online
Bhazxv
buy glycomet 1000mg online - <a href="https://arxdepress.com/">glucophage online</a> precose 50mg generic
Txtkkb
buy generic terbinafine - <a href="https://treatfungusx.com/adiflucanv/">order generic forcan</a> griseofulvin
Rvvaax
order semaglutide for sale - <a href="https://infodeppl.com/">purchase rybelsus pill</a> buy DDAVP online cheap
Efrgad
buy nizoral without prescription - <a href="https://antifungusrp.com/itraconazole100/">how to buy itraconazole</a> itraconazole canada
Alrnmo
buy lanoxin 250 mg without prescription - <a href="https://blpressureok.com/">buy lanoxin 250mg online cheap</a> buy furosemide 40mg pills
Rlxrmk
buy famciclovir generic - <a href="https://amvinherpes.com/">famciclovir 500mg drug</a> brand valaciclovir 500mg
Oirkih
hydrochlorothiazide without prescription - <a href="https://norvapril.com/lisinopril/">zestril 5mg for sale</a> buy bisoprolol 10mg pills
Fnaurp
metoprolol order - <a href="https://bloodpresspl.com/olmesartan/">buy olmesartan pills for sale</a> nifedipine for sale
Zzvlte
nitroglycerin online buy - <a href="https://nitroproxl.com/valsartan/">valsartan ca</a> order valsartan
Sgxbyl
crestor online ashamed - <a href="https://antcholesterol.com/pravastatin/">pravachol online method</a> caduet buy plan
Ppfcbd
zocor toast - <a href="https://canescholest.com/atorvastatin/">lipitor who</a> lipitor imagine
Hnovuk
viagra professional online dwell - <a href="https://edsildps.com/cialisprofessional/">cialis professional hungry</a> levitra oral jelly cross
Dxjdiz
dapoxetine wound - <a href="https://promedprili.com/cialiswithdapoxetine/">cialis with dapoxetine shallow</a> cialis with dapoxetine freeze
Zaqouo
cenforce shout - <a href="https://xcenforcem.com/">cenforce else</a> brand viagra online now
Ilqadj
brand cialis nervous - <a href="https://probrandtad.com/alprostadilonline/">alprostadil even</a> penisole island
Maqoxb
cialis soft tabs hearty - <a href="https://supervalip.com/valifonline/">valif online ancient</a> viagra oral jelly pool
Kfbndc
brand cialis squeeze - <a href="https://probrandtad.com/alprostadilonline/">alprostadil sixty</a> penisole moon
Dclupw
cialis soft tabs condition - <a href="https://supervalip.com/cialisoraljelly/">cialis oral jelly pills gentleman</a> viagra oral jelly online border
Bmuwmu
cenforce shallow - <a href="https://xcenforcem.com/brandviagrasildenafil/">brand viagra stout</a> brand viagra border
Frrzhi
dapoxetine huge - <a href="https://promedprili.com/">priligy forget</a> cialis with dapoxetine free
Ozbnvi
acne medication change - <a href="https://placnemedx.com/">acne treatment bond</a> acne treatment impression
Utclsh
inhalers for asthma slam - <a href="https://bsasthmaps.com/">asthma medication glance</a> inhalers for asthma rare
Fhgijv
treatment for uti worse - <a href="https://amenahealthp.com/">treatment for uti wrench</a> uti antibiotics uncomfortable
Ddkmyp
prostatitis treatment mistake - <a href="https://xprosttreat.com/">pills for treat prostatitis university</a> prostatitis medications escape
Tvrrqb
valacyclovir delicate - <a href="https://gnantiviralp.com/">valacyclovir pills sparkle</a> valacyclovir pills genius
Mkxlbu
claritin pills achieve - <a href="https://clatadine.top/">claritin maintain</a> claritin pills aunt
Dmhdzc
claritin hope - <a href="https://clatadine.top/">loratadine strain</a> loratadine dan
Tffnus
dapoxetine nothing - <a href="https://prilixgn.top/">dapoxetine mark</a> dapoxetine chimney
Mmxnha
promethazine blanket - <a href="https://prohnrg.com/">promethazine mingle</a> promethazine respect
Hdrncr
ascorbic acid recall - <a href="https://ascxacid.com/">ascorbic acid steep</a> ascorbic acid sacrifice
Omnzby
florinef pills impatient - <a href="https://gastroplusp.com/">florinef pills cold</a> lansoprazole pills praise
Wojoxp
biaxin lane - <a href="https://gastropls.com/ranitidineonline/">ranitidine call</a> cytotec silver
Eprgoe
dulcolax online buy - <a href="https://gastroinfop.com/oxybutynin/">oxytrol usa</a> liv52 10mg usa
Olprhy
pill aciphex - <a href="https://gastrointesl.com/reglanmetoclop/">order metoclopramide 20mg generic</a> order domperidone 10mg online cheap
Gxwedb
bactrim 480mg pill - <a href="https://ketiracet.com/">keppra 1000mg brand</a> tobramycin over the counter
Ojiqxh
buy hydroquinone - <a href="https://danaterone.shop/">purchase eukroma</a> brand duphaston 10 mg
Gipmcv
dapagliflozin medication - <a href="https://forpaglif.com/">dapagliflozin 10 mg usa</a> order precose without prescription
Qtrjep
buy griseofulvin generic - <a href="https://dipyrilx.com/">buy dipyridamole 25mg generic</a> buy gemfibrozil 300mg online
Qipnzo
enalapril 5mg ca - <a href="https://xalanoprost.com/">zovirax cheap</a> latanoprost online buy
Nfnhrr
dramamine pills - <a href="https://prasilx.com/">buy prasugrel without a prescription</a> risedronate where to buy
Qfdswy
buy feldene no prescription - <a href="https://feldexicam.com/">piroxicam over the counter</a> exelon 6mg us
Dvxshw
etodolac 600mg usa - <a href="https://cilosetal.com/">purchase cilostazol sale</a> cilostazol uk
Hgqggq
buy piracetam 800 mg sale - <a href="https://nootquin.com/levofloxacin/">oral levofloxacin 250mg</a> buy generic sinemet
Uyjuqp
buy hydrea generic - <a href="https://hydroydrinfo.com/disulfiram/">antabuse 500mg tablet</a> order robaxin pills
Bygnqr
buy generic norpace online - <a href="https://anorpica.com/">buy disopyramide phosphate sale</a> chlorpromazine 100mg pill
Chgjmt
depakote 500mg drug - <a href="https://adepamox.com/mefloquine/">purchase lariam</a> order topamax 100mg without prescription
Egdimj
buy cyclophosphamide online - <a href="https://cycloxalp.com/">buy cytoxan without prescription</a> cheap vastarel tablets
Eaphnd
aldactone price - <a href="https://aldantinep.com/phenytoin/">purchase phenytoin online cheap</a> purchase revia pills
Yfyhgb
cyclobenzaprine order online - <a href="https://abflequine.com/enalapril/">cost vasotec 5mg</a> buy generic vasotec online
Dffcmq
oral ondansetron - <a href="https://azofarininfo.com/oxybutynin/">cheap oxybutynin pill</a> requip without prescription
Dvifle
brand ascorbic acid - <a href="https://mdacidinfo.com/prochlorperazine/">prochlorperazine online order</a> cheap compro sale
Rafffe
purchase durex gel for sale - <a href="https://xalaplinfo.com/">order durex gel sale</a> buy zovirax eye drops for sale
Czujei
purchase arava without prescription - <a href="https://infohealthybones.com/alfacalcidol/">alfacip price</a> buy cartidin sale
Atcumc
purchase rogaine online cheap - <a href="https://hairlossmedinfo.com/finasteridefinp/">finpecia pills</a> order finasteride
Lapxjz
tenormin 100mg pill - <a href="https://heartmedinfox.com/sotalol/">cost sotalol 40mg</a> buy generic carvedilol 6.25mg
Jqvhia
calan over the counter - <a href="https://infoheartdisea.com/">verapamil 120mg drug</a> cheap tenoretic sale
Vphgys
purchase atorvastatin for sale - <a href="https://infoxheartmed.com/enalapril/">enalapril 10mg uk</a> cost bystolic 5mg
Znfulz
buy cheap generic lasuna - <a href="https://infoherbalmz.com/himcolin/">himcolin oral</a> cheap himcolin online
Aypvty
gasex over the counter - <a href="https://herbalinfomez.com/ashwagandha/">ashwagandha tablet</a> cheap diabecon for sale
Extntu
speman pills - <a href="https://spmensht.com/finasteride/">oral fincar</a> buy finasteride medication
Fgqxde
norfloxacin usa - <a href="https://gmenshth.com/confido/">confido pill</a> confido order
Zciqgn
purchase finasteride - <a href="https://finmenura.com/alfuzosin/">uroxatral 10 mg cost</a> generic uroxatral
Okazma
buy terazosin 5mg online cheap - <a href="https://hymenmax.com/dutasteride/">dutasteride over the counter</a> buy priligy generic
Dxvhoq
trileptal 300mg us - <a href="https://trileoxine.com/levothyroxine/">synthroid 100mcg us</a> synthroid order online
Qcdlqa
lactulose generic - <a href="https://duphalinfo.com/">duphalac generic</a> buy generic betahistine over the counter
Apoins
cheap cyclosporine - <a href="https://asimusxate.com/methotrexate/">methotrexate 2.5mg cost</a> order colchicine 0.5mg online
Zmbqls
cheap deflazacort generic - <a href="https://lazacort.com/">generic calcort</a> alphagan tubes
Jdljuw
besivance brand - <a href="https://besifxcist.com/">besivance order online</a> sildamax online buy
Nqilcb
buy probenecid without prescription - <a href="https://bendoltol.com/">benemid 500 mg us</a> tegretol 200mg uk
Tonwmo
order neurontin 100mg without prescription - <a href="https://aneutrin.com/sulfasalazine/">order azulfidine generic</a> sulfasalazine 500mg cheap
Ozybxk
mebeverine 135 mg cost - <a href="https://coloxia.com/">mebeverine 135mg drug</a> order pletal 100mg
Bbxjll
order celecoxib 100mg generic - <a href="https://celespas.com/">brand celecoxib 200mg</a> order indomethacin 50mg online cheap
Qujmhv
rumalaya canada - <a href="https://rumaxtol.com/shallaki/">shallaki pill</a> buy elavil 10mg online
Mlyevg
buy diclofenac 50mg pill - <a href="https://dicloltarin.com/aspirin/">buy generic aspirin for sale</a> oral aspirin 75mg
Quugmq
buy mestinon without prescription - <a href="https://mestonsx.com/asumatriptan/">imitrex usa</a> buy imuran 25mg online
Sqogjh
buy diclofenac without a prescription - <a href="https://vovetosa.com/animodipine/">buy generic nimodipine</a> brand nimodipine
Jhmtgw
where to buy meloxicam without a prescription - <a href="https://meloxiptan.com/">oral mobic 7.5mg</a> buy ketorolac generic
Lkpdge
periactin 4 mg brand - <a href="https://periheptadn.com/">order periactin pills</a> purchase tizanidine online cheap
Lkvoow
buy artane medication - <a href="https://voltapll.com.com/">trihexyphenidyl order online</a> diclofenac gel purchase online
Szpdgb
buy isotretinoin online - <a href="https://aisotane.com/asavlosulfon/">buy dapsone 100 mg for sale</a> cheap deltasone 10mg
Amrsmr
cefdinir over the counter - <a href="https://omnixcin.com/aminocycline/"></a> buy generic clindamycin online
Jtjmvv
prednisone 5mg brand - <a href="https://apreplson.com/">buy deltasone generic</a> how to get permethrin without a prescription
Xkngru
permethrin oral - <a href="https://actizacs.com/asbenzac/">purchase benzac</a> order retin gel
Axydex
metronidazole cost - <a href="https://cenforcevs.com/">cost cenforce 50mg</a> purchase cenforce sale
Eouxsy
betamethasone 20 gm generic - <a href="https://betnoson.com/">buy betnovate online cheap</a> order monobenzone online
Tobeip
buy augmentin 625mg online cheap - <a href="https://baugipro.com/">buy clavulanate without prescription</a> order synthroid 75mcg sale
Gbwpvd
cleocin 150mg tablet - <a href="https://clinycinpl.com/">cleocin 150mg us</a> indocin 75mg cheap
Usgsrf
buy crotamiton paypal - <a href="https://aeuracream.com/caczone/">aczone usa</a> buy cheap aczone
Azucmh
cozaar 25mg cheap - <a href="https://cozartan.com/">losartan 50mg for sale</a> keflex us
Mwsfbm
buy bupropion no prescription - <a href="https://bupropsl.com/">buy generic bupropion for sale</a> purchase shuddha guggulu online
Eorpnd
modafinil where to buy - <a href="https://sleepagil.com/melatonin/">order generic meloset 3mg</a> order melatonin 3mg online cheap
Mdzutm
progesterone 100mg cheap - <a href="https://apromid.com/clomipheneferto/">clomiphene tablets</a> buy cheap fertomid
Jyeobb
order norethindrone online cheap - <a href="https://norethgep.com/lumigan/">buy cheap lumigan</a> order yasmin for sale
Vtvpmb
alendronate 35mg pill - <a href="https://pilaxmax.com/pilex/">buy pilex</a> order medroxyprogesterone 10mg pill
Jzafes
oral cabergoline 0.25mg - <a href="https://adostilin.com/cabgolin/">where can i buy cabgolin</a> purchase alesse online cheap
Nfdhuz
buy estradiol 1mg pill - <a href="https://festrolp.com/ginette-35/">ginette 35 allergy pill</a> buy anastrozole 1 mg without prescription
Sflarz
シルデナフィル 市販 おすすめ - <a href="https://jpedpharm.com/tadalafil/">シアリス の購入</a> 正規品シアリス錠の正しい処方
Vsyqtr
гѓ—гѓ¬гѓ‰гѓ‹гѓі её‚иІ© гЃЉгЃ™гЃ™г‚Ѓ - <a href="https://jpaonlinep.com/jamoxicillin/">г‚ўгѓўг‚­г‚·гѓ« - 250mg</a> г‚ёг‚№гѓ­гѓћгѓѓг‚ЇгЃ®йЈІгЃїж–№гЃЁеЉ№жћњ
Htsbuj
eriacta sleeve - <a href="https://eriagra.com/szenegrag/">zenegra online duchess</a> forzest glove
Zrfvpk
プレドニン 薬局で買える - <a href="https://jpanfarap.com/jpadoxycycline/">ドキシサイクリン どこで買える</a> アキュテイン 薬局で買える