欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序學習筆記之跳轉頁面、傳遞參數獲得數據操作圖文詳解

 更新時間:2019年03月28日 12:06:18   作者:李維山  
這篇文章主要介紹了微信小程序學習筆記之跳轉頁面、傳遞參數獲得數據操作,結合實例形式分析了微信小程序基于navigator組件的頁面跳轉及數據傳遞相關操作技巧,并結合圖文形式進行詳細說明,需要的朋友可以參考下

本文實例講述了微信小程序學習筆記之跳轉頁面、傳遞參數獲得數據操作。分享給大家供大家參考,具體如下:

前面一篇介紹了微信小程序表單提交與PHP后臺數據交互處理。現在需要實現點擊博客標題或縮略圖,跳轉到博客詳情頁面。

開始想研究一下微信小程序的web-view組件跳轉傳參,把網頁嵌入到小程序,結果看到官方文檔的一句話打消了念頭,因為沒有認證......

【方法一 使用navigator組件跳轉傳參】

前臺博客列表頁面data.wxml:(后臺數據交互參考上一篇)

<view wx:for="{{artinfo}}" wx:for-item="artinfo">
  <view>
    <navigator url="/pages/detial/detial?article_id={{artinfo.article_id}}" >
     {{artinfo.article_title}}
    </navigator>
  </view>
  <navigator url="/pages/detial/detial?article_id={{artinfo.article_id}}" >
   <image src="{{artinfo.thumbnail}}"></image>
  </navigator>
</view>

前臺博客詳情頁面detail.js:

Page({
 onLoad: function (options) { //options:頁面跳轉所傳的參數
  var that = this
  wx.request({
   url: 'https://www.msllws.top/Getdata/detial',
   data: {
    'article_id': options.article_id
   },
   method: 'POST',
   header: {
    'Content-Type': 'application/x-www-form-urlencoded'
   },
   success: function (res) {
    if (res.data.state == 1) {
     that.setData({
      artinfo: res.data.data
     })
    }else{
     wx.showToast({
      title: res.data.msg
     });
    }
   }
  })
 }
})

前臺博客詳情頁面detail.wxml:

<view>{{artinfo.article_title}}</view>
<view>———————————————————————————</view>
<rich-text nodes="{{artinfo.article_content}}"></rich-text>

后臺獲取博客內容接口:(tp5)

 public function detial()
 { 
   $arr = array('state'=>0,'msg'=>'','data'=>array());
   $article_id = $_POST['article_id'];
   if($article_id){
     $whe['article_id'] = $article_id;
     $artinfo = db('article')->field('`article_title`,`article_content`')->where($whe)->find();
     if($artinfo){
       $arr['state'] = 1;
       $arr['msg'] = 'success';
       $arr['data'] = $artinfo;
     }else{
       $arr['msg'] = '沒有信息';
     }
   }else{
     $arr['msg'] = '參數錯誤';
   }
   echo json_encode($arr);die;
 }

實現效果如下:

【方法二 使用wx.navigateTo API跳轉傳參】

前臺博客列表頁面data.wxml:

(data-xxx:自定義參數屬性,catchtap:綁定點擊事件)

<view wx:for="{{artinfo}}" wx:for-item="artinfo">
  <view data-article_id="{{artinfo.article_id}}" catchtap="showDetial">
     {{artinfo.article_title}}
   </view>
  <view data-article_id="{{artinfo.article_id}}" catchtap="showDetial">
   <image src="{{artinfo.thumbnail}}"></image>
  </view>
</view>

前臺博客列表頁面data.js:

Page({
 onLoad: function () {
  var that = this
  wx.request({
   url: 'https://www.msllws.top/Getdata',
   headers: {
    'Content-Type': 'application/json'
   },
   success: function (res) {
    that.setData({
     artinfo: res.data
    })
   }
  })
 },
 showDetial: function (e) {
  var article_id = e.currentTarget.dataset.article_id;
  wx.navigateTo({
   url: '/pages/detial/detial?article_id=' + article_id
  })
 }
})

其他與方法一相同,可實現與方法一相同跳轉傳參。

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

相關文章

最新評論