微信小程序文章詳情功能完整實(shí)例
本文實(shí)例講述了微信小程序文章詳情功能。分享給大家供大家參考,具體如下:
接著上一篇
http://chabaoo.cn/article/187900.htm
list.js 首先獲取文章的id,因?yàn)槲覀兊臄?shù)據(jù)是假數(shù)據(jù)所以用key值作為文章id
onPostTap: function (event) { var article_id = event.currentTarget.dataset.aid; wx.navigateTo({ url: '../article-detail/detail?aid=' + article_id, }) },
detail.wxml
<!--pages/article-detail/detail.wxml--> <view> <image src="/images/post/sls.jpg" class="detail-img"></image> </view> <view class="avatar"> <image src="/images/avatar/2.png"></image> <text>{{detail.avatar}}</text> <text>發(fā)表于 {{detail.date}}</text> <image src="/images/icon/collection-anti.png"></image> <image src="/images/icon/share.png"></image> </view> <view class="title"> <text>{{detail.title}}</text> </view> <view class="content"> {{detail.content}} </view> <view class="pre-next"> <text class="pre">上一篇:啊啊啊啊啊啊啊</text><text class="next">下一篇:哈哈哈哈哈</text> </view>
detail.wxss
/* pages/article-detail/detail.wxss */ .detail-img { width: 100%; height: 400rpx; } .avatar { overflow: hidden; } .avatar image { float: left; width: 100rpx; height: 100rpx; margin-left: 20rpx; } .avatar image:nth-child(4) { float: right; width: 60rpx; height: 60rpx; margin-right: 20rpx; } .avatar image:nth-child(5) { float: right; width: 60rpx; height: 60rpx; vertical-align: middle; } .avatar text { float: left; font-size: 30rpx; height: 100rpx; line-height: 100rpx; padding-left: 15rpx; } .avatar text:nth-child(3) { font-size: 25rpx; color: gainsboro; } .title { width: 100%; clear: both; } .title text { display: flex; justify-content: center; align-items: center; color: rgb(171, 211, 224); font-size: 50rpx; } .content{ color:#666; letter-spacing: 2rpx; margin-top:20rpx; padding-left:20rpx; padding-right:20rpx; line-height:40rpx; font-size:25rpx; text-indent:50rpx; } .pre-next{ margin-top:20rpx; } .pre{ float:left; margin-left:20rpx; font-size: 25rpx; color:rgb(171, 211, 224); padding-bottom: 20rpx; } .next{ float: right; margin-right:20rpx; font-size: 25rpx; color:rgb(171, 211, 224); padding-bottom: 20rpx; }
detail.js
// pages/article-detail/detail.js var articleData = require("/../../data/article-data.js"); Page({ /** * 頁(yè)面的初始數(shù)據(jù) */ data: { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 */ onLoad: function (options) { //獲取文章的id var aid = options.aid; var article = articleData.data[aid]; this.setData({detail:article}); }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成 */ onReady: function () { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示 */ onShow: function () { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏 */ onHide: function () { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載 */ onUnload: function () { }, /** * 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶(hù)下拉動(dòng)作 */ onPullDownRefresh: function () { }, /** * 頁(yè)面上拉觸底事件的處理函數(shù) */ onReachBottom: function () { }, /** * 用戶(hù)點(diǎn)擊右上角分享 */ onShareAppMessage: function () { } })
希望本文所述對(duì)大家微信小程序設(shè)計(jì)有所幫助。
相關(guān)文章
JS中數(shù)組常用的循環(huán)遍歷你會(huì)幾種
JS 遍歷數(shù)組(循環(huán)數(shù)組)的方式有多種,但你都知道嗎?下面這篇文章主要給大家介紹了關(guān)于JS中數(shù)組常用循環(huán)遍歷的相關(guān)資料,需要的朋友可以參考下2021-06-06js實(shí)現(xiàn)移動(dòng)端簡(jiǎn)易滑動(dòng)表格
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)移動(dòng)端簡(jiǎn)易滑動(dòng)表格,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02關(guān)于JavaScript回調(diào)函數(shù)的深入理解
由于函數(shù)是一等對(duì)象,我們可以把一個(gè)函數(shù)作為參數(shù)傳遞給另一個(gè)函數(shù),然后在那個(gè)函數(shù)內(nèi)執(zhí)行,至也可以被那個(gè)函數(shù)返回,然后再執(zhí)行,這篇文章主要給大家介紹了關(guān)于JavaScript回調(diào)函數(shù)的深入理解,需要的朋友可以參考下2021-06-06D3.js實(shí)現(xiàn)拓?fù)鋱D的示例代碼
本篇文章主要介紹了D3.js實(shí)現(xiàn)拓?fù)鋱D的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-06-06