文章详情页面动态显示(即点击某个文章就跳转到相应文章的详情页):
思路:在文章列表页面添加catchtop事件,在js文件中获取文章的index,并用wx.navigateTo中的
url拼接详情页的地址和文章的index,(在该操作之前该js应该已引入静态数据,在data中定义相应数据,
并更新数据,在详情页的js中也同样如上,详情看demo),列表页面事件添加完毕后,详情页需要接收数据
(index和文章内容),这就用到了,详情页的生命周期函数options来接收值.

为每个文章添加事件:

<block wx:for='{{listArr}}' wx:key='{{index}}'>
<view catchtap="toDetail" data-index='{{index}}'>
<template is='listTmp' data='{{...item}}'/>
</view>
</block>

detail.wxml代码如下:

<!--pages/detail/detail.wxml-->
<view class="detailContainer">
<image class="headImg" src="{{detailObj.detail_img}}"></image>
<view class="avatar_date">
<image src="{{detailObj.avatar}}"></image>
<text>{{detailObj.author}}</text>
<text>发布于</text>
<text>{{detailObj.data}}</text>
</view>
<text class="company">{{detailObj.title}}</text>
<view class="collection_share_container">
<view class="collection_share">
<image src="/static/images/sc.png"></image>
<image src="/static/images/share2.png"></image>
</view>
<view class="line"></view>
</view>
<button>转发此文章</button>
<text class="content">{{detailObj.detail_content}}</text>
</view>

detail.js代码如下:

// pages/detail/detail.js
let datas=require('../data/list-data.js');
console.log(datas);
Page({ /**
* 页面的初始数据
*/
data: {
datailObj:{},
index:null
}, /**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options);
//获取list页面传来的参数值
let index = options.index;
//更新data中的detailObj的状态值
this.setData({
detailObj:datas.list_data[index],
index //同名参数值可以省略不写(index:index)
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () { }, /**
* 生命周期函数--监听页面显示
*/
onShow: function () { },

微信小程序(七)文章详情页面动态显示的更多相关文章

  1. 微信小程序左右滑动切换页面示例代码--转载

    微信小程序——左右滑动切换页面事件 微信小程序的左右滑动触屏事件,主要有三个事件:touchstart,touchmove,touchend. 这三个事件最重要的属性是pageX和pageY,表示X, ...

  2. 微信小程序(七)-项目实例(原生框架 MINA转云开发)==02-云开发-配置

    云开发:1.就是用云函数的型式来使用云存储和云数据库完成各种操作!     2.只关注调什么函数,完成什么功能即可,无需关心HTTP请求哪一套!     3.此模式不代表没有服务器,只是部署在云环境中 ...

  3. 微信小程序开发07-列表页面怎么做

    接上文:微信小程序开发06-一个业务页面的完成 github地址:https://github.com/yexiaochai/wxdemo 我们首页功能基本完成,我对比了下实际工作中的需求,完成度有7 ...

  4. 微信小程序:设置启动页面

    一.功能描述 微信小程序启动时,首先运行app.js,然后才跳转到第一个页面,也就是启动界面. 设置启动界面,只需要调整app.json的pages信息的位置,放在第一条的page记录便是启动界面

  5. 微信小程序入门 第一个页面搭建

    首先搭建首页 微信小程序与web程序非常相似  有非常多的组件  多个组件形成一个页面 每个组件有自己一些特殊的属性来控制显示效果 通过js注册事件控制响应 首先使用swiper实现一个banner轮 ...

  6. 【微信】微信小程序 应用内的页面跳转在添加了tab以后就跳转不成功的问题解决

    在微信小程序中,本来应用页面内绑定在按钮上跳转页面可以成功,但是将页面添加在tab以后就不能实现跳转了 原本代码如下: //事件处理函数 bindViewTap: function() { wx.na ...

  7. 微信小程序开发过程中tabbar页面显示的相关问题及解决办法!

    在微信小程序的开发过程中如果有使用过tabbar的同学,我相信一定会遇到一些困扰.为什么有些时候代码中明明已经在app.json里面增加了tabbar,可以页面中就是不显示呢?可不可以有些页面显示ta ...

  8. 微信小程序(13)--页面滚动到某个位置添加类效果

    微信小程序页面滚动到某个位置添加类,盒子置顶效果. <!-- vh,是指CSS中相对长度单位,表示相对视口高度(Viewport Height),1vh = % * 视口高度 --> &l ...

  9. 微信小程序(3)--页面跳转和提示框

    微信小程序页面跳转方法: 1.<navigator url="../test/test"><button>点我可以切换可以返回</button> ...

随机推荐

  1. MySQL 数据库在 Windows 下修复 only_full_group_by 的错误

    本机上新安装了个MySQL数据库,在插入数据的时候一直提示这个错误: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY ...

  2. [Swift]LeetCode209. 长度最小的子数组 | Minimum Size Subarray Sum

    Given an array of n positive integers and a positive integer s, find the minimal length of a contigu ...

  3. [Swift]LeetCode485. 最大连续1的个数 | Max Consecutive Ones

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

  4. [SQL]LeetCode601. 体育馆的人流量 | Human Traffic of Stadium

    SQL架构 Create table If Not Exists stadium (id int, visit_date DATE NULL, people int) Truncate table s ...

  5. [Swift]LeetCode781. 森林中的兔子 | Rabbits in Forest

    In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how ...

  6. [Swift]LeetCode830. 较大分组的位置 | Positions of Large Groups

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...

  7. python学习笔记(十)、文件操作

    在前面我们了解到了没得模块,其中有一个模块为fileinput,为文件操作模块,不知道小伙伴们是否还记得? 1 打开文件 要打开文件,可以使用fileinput中的fileinput.input函数进 ...

  8. CardView卡片式布局

    CardView适用于实现卡片式布局效果的重要控件,由appcompat-v7库提供,实际上CardView也是一个FrameLayout,只是额外提供了圆角和阴影效果,看上去有立体的感觉.一般Car ...

  9. CentOS 6下安装Python2.7

    安装方法 如果在CentOS上自己编译安装过python2.7,使用过程中会发现有些标准库没有安装之类的问题. 逛别人博客的时候发现,一个便捷的方法:使用RHSCL的全称是Red Hat Softwa ...

  10. [React] react+redux+router+webpack+antd环境搭建一版

    好久之前搭建的一个react执行环境,受历史影响是webpack3.10.0和webpack-dev-server2.7.1的环境,新项目准备用webpack4重新弄弄了,旧的记录就合并发布了(在没有 ...