微信小程序文章詳情功能完整實例
更新時間:2020年06月03日 09:22:32 作者:huangyuxin_
這篇文章主要介紹了微信小程序文章詳情功能,結(jié)合完整實例形式詳細分析了微信小程序文章詳情功能具體步驟、原理及功能實現(xiàn)技巧,需要的朋友可以參考下
本文實例講述了微信小程序文章詳情功能。分享給大家供大家參考,具體如下:
接著上一篇
http://www.dbjr.com.cn/article/187900.htm
list.js 首先獲取文章的id,因為我們的數(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({ /** * 頁面的初始數(shù)據(jù) */ data: { }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function (options) { //獲取文章的id var aid = options.aid; var article = articleData.data[aid]; this.setData({detail:article}); }, /** * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 */ onReady: function () { }, /** * 生命周期函數(shù)--監(jiān)聽頁面顯示 */ onShow: function () { }, /** * 生命周期函數(shù)--監(jiān)聽頁面隱藏 */ onHide: function () { }, /** * 生命周期函數(shù)--監(jiān)聽頁面卸載 */ onUnload: function () { }, /** * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動作 */ onPullDownRefresh: function () { }, /** * 頁面上拉觸底事件的處理函數(shù) */ onReachBottom: function () { }, /** * 用戶點擊右上角分享 */ onShareAppMessage: function () { } })
希望本文所述對大家微信小程序設(shè)計有所幫助。
相關(guān)文章
關(guān)于JavaScript回調(diào)函數(shù)的深入理解
由于函數(shù)是一等對象,我們可以把一個函數(shù)作為參數(shù)傳遞給另一個函數(shù),然后在那個函數(shù)內(nèi)執(zhí)行,至也可以被那個函數(shù)返回,然后再執(zhí)行,這篇文章主要給大家介紹了關(guān)于JavaScript回調(diào)函數(shù)的深入理解,需要的朋友可以參考下2021-06-06