微信小程序?qū)W習(xí)筆記之跳轉(zhuǎn)頁(yè)面、傳遞參數(shù)獲得數(shù)據(jù)操作圖文詳解
本文實(shí)例講述了微信小程序?qū)W習(xí)筆記之跳轉(zhuǎn)頁(yè)面、傳遞參數(shù)獲得數(shù)據(jù)操作。分享給大家供大家參考,具體如下:
前面一篇介紹了微信小程序表單提交與PHP后臺(tái)數(shù)據(jù)交互處理?,F(xiàn)在需要實(shí)現(xiàn)點(diǎn)擊博客標(biāo)題或縮略圖,跳轉(zhuǎn)到博客詳情頁(yè)面。
開始想研究一下微信小程序的web-view組件跳轉(zhuǎn)傳參,把網(wǎng)頁(yè)嵌入到小程序,結(jié)果看到官方文檔的一句話打消了念頭,因?yàn)闆]有認(rèn)證......
【方法一 使用navigator組件跳轉(zhuǎn)傳參】
前臺(tái)博客列表頁(yè)面data.wxml:(后臺(tái)數(shù)據(jù)交互參考上一篇)
<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>
前臺(tái)博客詳情頁(yè)面detail.js:
Page({ onLoad: function (options) { //options:頁(yè)面跳轉(zhuǎn)所傳的參數(shù) 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 }); } } }) } })
前臺(tái)博客詳情頁(yè)面detail.wxml:
<view>{{artinfo.article_title}}</view> <view>———————————————————————————</view> <rich-text nodes="{{artinfo.article_content}}"></rich-text>
后臺(tái)獲取博客內(nèi)容接口:(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'] = '參數(shù)錯(cuò)誤'; } echo json_encode($arr);die; }
實(shí)現(xiàn)效果如下:
【方法二 使用wx.navigateTo API跳轉(zhuǎn)傳參】
前臺(tái)博客列表頁(yè)面data.wxml:
(data-xxx:自定義參數(shù)屬性,catchtap:綁定點(diǎn)擊事件)
<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>
前臺(tái)博客列表頁(yè)面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 }) } })
其他與方法一相同,可實(shí)現(xiàn)與方法一相同跳轉(zhuǎn)傳參。
希望本文所述對(duì)大家微信小程序開發(fā)有所幫助。
- 微信小程序 動(dòng)態(tài)修改頁(yè)面數(shù)據(jù)及參數(shù)傳遞過程詳解
- 微信小程序?qū)崿F(xiàn)頁(yè)面跳轉(zhuǎn)傳遞參數(shù)(實(shí)體,對(duì)象)
- 微信小程序?qū)崿F(xiàn)傳遞多個(gè)參數(shù)與事件處理
- 微信小程序之頁(yè)面跳轉(zhuǎn)和參數(shù)傳遞的實(shí)現(xiàn)
- 微信小程序教程系列之頁(yè)面跳轉(zhuǎn)和參數(shù)傳遞(6)
- 微信小程序開發(fā)之?dāng)?shù)據(jù)存儲(chǔ) 參數(shù)傳遞 數(shù)據(jù)緩存
- 微信小程序 navigator 跳轉(zhuǎn)url傳遞參數(shù)
- 微信小程序之間的參數(shù)傳遞、獲取的操作方法
相關(guān)文章
微信小程序 websocket 實(shí)現(xiàn)SpringMVC+Spring+Mybatis
這篇文章主要介紹了 微信小程序websocket實(shí)現(xiàn)SpringMVC+Spring+Mybatis的相關(guān)資料,這里提供實(shí)現(xiàn)思路及實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-08-08詳解JavaScript中的類型判斷與類型轉(zhuǎn)換
這篇文章主要給大家講解一下JavaScript中的類型判斷與類型轉(zhuǎn)換的基本概念和使用方法,對(duì)我們的學(xué)習(xí)JavaScript的類型判斷與轉(zhuǎn)換有一定的幫助,需要的朋友可以參考下2023-07-07原生JS面向?qū)ο髮?shí)現(xiàn)打磚塊小游戲
這篇文章主要為大家詳細(xì)介紹了原生JS面向?qū)ο髮?shí)現(xiàn)打磚塊小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-09-09JavaScript判斷空值、NULL、undefined的方法對(duì)比
JavaScript五種原始類型(boolean、number、string、null、undefined)中的一種。在鑒別JavaScript原始類型的時(shí)候我們會(huì)用到typeof操作符。Typeof操作符可用于字符串、數(shù)字、布爾和未定義類型。2022-12-12JavaScript類的繼承方法小結(jié)【組合繼承分析】
這篇文章主要介紹了JavaScript類的繼承方法,結(jié)合實(shí)例形式總結(jié)分析了JavaScript繼承的概念、原理及組合繼承相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-07-07js 賦值包含單引號(hào)雙引號(hào)問題的解決方法
這篇文章主要介紹了js賦值包含單引號(hào)雙引號(hào)問題的解決方法,需要的朋友可以參考下2014-02-02