微信小程序文章詳情頁(yè)跳轉(zhuǎn)案例詳解
前面寫了一篇小程序訪問公眾號(hào)文章
里面所有的文章列表里面都是跳轉(zhuǎn)了同一篇文章鏈接,那么,如果所有的列表跳轉(zhuǎn)詳情頁(yè)的時(shí)候,跳轉(zhuǎn)對(duì)應(yīng)id所在的文章又該怎么寫?
index.html
<view class="container"> <view wx:for="{{cardTeams}}" wx:key="{{index}}" wx:for-item="cardTeam" class="item"> <image class="img" src="{{cardTeam.imgsrc}}" mode="scaleToFill"></image> <view class="number-wrapper"> <text class="name">{{cardTeam.name}}</text> <view class="count-wrapper"> <text class="count">{{cardTeam.count}}</text> </view> <view class="details"> <navigator url="../details/details?goodsId={{index}}">查看詳情</navigator> </view> </view> </view> </view>
index.wxss
.container { padding-top: 0; } .item { width: 100%; height: 220rpx; position: relative; display: flex; margin: 10rpx 10rpx; border-bottom: 1px solid rgb(197, 199, 199); } .item:first-child { margin-top: 0; } .item .remove { width: 60px; height: 100%; background-color: red; position: absolute; top: 0; right: -60px; display: flex; justify-content: center; align-items: center; } .item .number-wrapper { padding-top: 25rpx; flex-direction: column; justify-content: space-between; } .item .ok { width: 60px; height: 100%; padding-right: 20rpx; display: flex; justify-content: center; align-items: center; background-color: #98f5ff; } .item .img { width: 150rpx; height: 150rpx; padding: 20rpx; } .number-wrapper .name { margin: 10rpx 10rpx 10rpx 10rpx; font-size: 39rpx; overflow: hidden; } .number-wrapper .count-wrapper { display: flex; align-items: center; margin-left: 10rpx; font-size: 25rpx; } .number-wrapper .count-wrapper .decrease-btn { font-size: 30rpx; } .number-wrapper .count-wrapper .increase-btn { font-size: 30rpx; } .number-wrapper .count-wrapper .count { margin: 0 1rpx 0 1rpx; font-size: 30rpx; } .number-wrapper .price-wrapper .people { margin-left: 250rpx; font-size: 30rpx; } /* 搜索框樣式 */ .view-search { display: flex; flex-direction: row; height: 70rpx; margin: 20rpx; padding: 5rpx; border: 1px #e4e2e2 solid; border-width: thin; align-items: center; } .input { flex: 1; height: 60rpx; } .input-placeholder { color: #999; } .button { width: 60rpx; height: 60rpx; } .details{ font-size: 36rpx; color:red; }
index.js
//index.js //獲取應(yīng)用實(shí)例 var app = getApp(); var cardTeams; Page({ data: { cardTeams: [{ "viewid": "1", "imgsrc": "https://13373313365.com/image/1.png", "price": "¥1245", "count": "為什么說(shuō) C 語(yǔ)言比 Java 難? ", "name": "為什么說(shuō) C 語(yǔ)言比 Java 難? ", }, { "viewid": "2", "imgsrc": "https://13373313365.com/image/1.png", "price": "¥2345", "count": "小程序云開發(fā)入門實(shí)戰(zhàn)總結(jié) ", "name": "小程序云開發(fā)入門實(shí)戰(zhàn)總結(jié) ", }, { "viewid": "3", "imgsrc": "https://13373313365.com/image/3.png", "price": "¥2345", "count": "node.js寫一個(gè)小爬蟲 ", "name": "node.js寫一個(gè)小爬蟲 ", }, { "viewid": "4", "imgsrc": "https://13373313365.com/image/3.png", "price": "¥2345", "count": "推薦一個(gè)前端開源項(xiàng)目 ", "name": "推薦一個(gè)前端開源項(xiàng)目 ", } ] }, onLoad: function () { // console.log('onLoad:' + app.globalData.domain) } })
詳情頁(yè)面
details.wxml
<web-view src="{{url}}"></web-view>
details.js
Page({ data: { url:'', //下面是先進(jìn)行存儲(chǔ)的不同產(chǎn)品數(shù)據(jù); productsList: [ { showDesc: 'https://mp.weixin.qq.com/s?__biz=MzI2ODUxMzg4Nw==&mid=2247485838&idx=1&sn=1208bcca91141b2c16c2e844efb67a41&chksm=eaef2ebedd98a7a8720092c3f2e87a7f3514d2140bdb7dea289d389aacdc55d268285897872b&token=1964115409&lang=zh_CN#rd' }, { showDesc: 'https://mp.weixin.qq.com/s?__biz=MzI2ODUxMzg4Nw==&mid=2247485869&idx=1&sn=7e4cedf5230c930cf18c9aa4683d1a43&chksm=eaef2e9ddd98a78bcd55835cba8e31f886df27319be99ac4710a0eace7fc8f196e081b03ad11&token=1964115409&lang=zh_CN#rd' }, {showDesc: 'https://mp.weixin.qq.com/s?__biz=MzI2ODUxMzg4Nw==&mid=2247485900&idx=1&sn=5aa1e6028f6499a611fff1ec2a641bf6&chksm=eaef2efcdd98a7eaeb618e687ed3f36cf5f9085779e0a130a8515ce46d8a444b08595dc15994&token=1964115409&lang=zh_CN#rd' }, { showDesc: 'https://mp.weixin.qq.com/s?__biz=MzI2ODUxMzg4Nw==&mid=2247485848&idx=1&sn=af73f05a22febcb4dfae60b197a6ca8e&chksm=eaef2ea8dd98a7bee88721a853d7dfce17387d11a371ba27295bec502b2f7ea76b2fd6faf34c&token=1964115409&lang=zh_CN#rd' }, ] }, /** * 生命周期函數(shù)--監(jiān)聽頁(yè)面加載 */ onLoad: function (options) { var goodsId = options.goodsId; console.log(goodsId) this.setData({ url: this.data.productsList[goodsId].showDesc }); } })
樣式可以自己進(jìn)行優(yōu)化,然后其中的道理就不一一細(xì)說(shuō)了,根據(jù)index點(diǎn)擊的列表的id判斷所對(duì)應(yīng)的url即可。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript實(shí)現(xiàn)帶粒子效果的進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)帶粒子效果的進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06javascript實(shí)現(xiàn)頁(yè)面刷新時(shí)自動(dòng)清空表單并選中的方法
這篇文章主要介紹了javascript實(shí)現(xiàn)頁(yè)面刷新時(shí)自動(dòng)清空表單并選中的方法,涉及javascript中reset與focus方法的相關(guān)使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07javascript簡(jiǎn)單實(shí)現(xiàn)跟隨滾動(dòng)條漂浮的返回頂部按鈕效果
這篇文章主要介紹了javascript簡(jiǎn)單實(shí)現(xiàn)跟隨滾動(dòng)條漂浮的返回頂部按鈕效果,涉及javascript基于onscroll事件動(dòng)態(tài)改變頁(yè)面元素樣式的相關(guān)技巧,需要的朋友可以參考下2016-08-08小程序中讀取騰訊文檔的表格數(shù)據(jù)的實(shí)現(xiàn)
本文主要介紹了小程序中讀取騰訊文檔的表格數(shù)據(jù)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07微信小程序使用setData修改數(shù)組中單個(gè)對(duì)象的方法分析
這篇文章主要介紹了微信小程序使用setData修改數(shù)組中單個(gè)對(duì)象的方法,結(jié)合具體實(shí)例形式分析了setData進(jìn)行數(shù)組修改的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-12-12使用JS前端技術(shù)實(shí)現(xiàn)靜態(tài)圖片局部流動(dòng)效果
本文使用前端開發(fā)技術(shù),結(jié)合?SVG?和?CSS?來(lái)實(shí)現(xiàn)類似的液化流動(dòng)效果,包含的知識(shí)點(diǎn)主要包括:mask-image?遮罩、feTurbulence?和?feDisplacementMap?濾鏡、filter?屬性、canvas?繪制方法、TimelineMax?動(dòng)畫及input[type=file]?本地圖片資源加載,需要的朋友可以參考下2022-08-08