Home  >  Article  >  WeChat Applet  >  WeChat applet page jump and return and return data

WeChat applet page jump and return and return data

高洛峰
高洛峰Original
2017-02-25 09:27:592500browse

WeChat applet explains page jump and return and returns data

A page:

.wxml file

<view class="flex-wrp">
    <text style="width: 32%;">选择城市</text>
    <input style="width: 68%;" type="text" bindtap="city" placeholder="请选择城市" value="{{cityName}}"/>
   </view>

.js file

Page({
 data: {
  cityName:"深圳"  #用来回传的关键字,默认深圳
 },
 city: function(e){
  wx.navigateTo({
    url: &#39;../city/city&#39;
  })
 }

})

After page A jumps to page B, it returns:

cityNameClick: function (event) {
  var cityName = event.currentTarget.dataset.cityname;
  console.log(cityName);

  var pages = getCurrentPages();
  var currPage = pages[pages.length - 1];  //当前页面
  var prevPage = pages[pages.length - 2]; //上一个页面

  //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  prevPage.setData({
   cityName: cityName
  })

  wx.navigateBack();
 },

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

For more articles related to WeChat applet page jump and return and return data, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn