微信小程序文章详情页跳转案例详解

所属分类: 网络编程 / JavaScript 阅读数: 1728
收藏 0 赞 0 分享

前面写了一篇小程序访问公众号文章

里面所有的文章列表里面都是跳转了同一篇文章链接,那么,如果所有的列表跳转详情页的时候,跳转对应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
//获取应用实例
var app = getApp();
var cardTeams;
Page({
 data: {
 cardTeams: [{
  "viewid": "1",
  "imgsrc": "https://13373313365.com/image/1.png",
  "price": "¥1245",
  "count": "为什么说 C 语言比 Java 难? ",
  "name": "为什么说 C 语言比 Java 难? ",
 }, {
  "viewid": "2",
  "imgsrc": "https://13373313365.com/image/1.png",
  "price": "¥2345",
  "count": "小程序云开发入门实战总结 ",
  "name": "小程序云开发入门实战总结 ",
 }, {
  "viewid": "3",
  "imgsrc": "https://13373313365.com/image/3.png",
  "price": "¥2345",

  "count": "node.js写一个小爬虫 ",
  "name": "node.js写一个小爬虫 ",
 }, {
  "viewid": "4",
  "imgsrc": "https://13373313365.com/image/3.png",
  "price": "¥2345",
  "count": "推荐一个前端开源项目 ",
  "name": "推荐一个前端开源项目 ",
 }
 ]
 },
 onLoad: function () {
 // console.log('onLoad:' + app.globalData.domain)
 }
})

详情页面

details.wxml

<web-view src="{{url}}"></web-view>

details.js

Page({
 data: {
 url:'',
 //下面是先进行存储的不同产品数据;
 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' },

 ]
 },

 /**
 * 生命周期函数--监听页面加载
 */
 onLoad: function (options) {
 
 var goodsId = options.goodsId;
 console.log(goodsId)
 this.setData({
  url: this.data.productsList[goodsId].showDesc
 });
 }
})

样式可以自己进行优化,然后其中的道理就不一一细说了,根据index点击的列表的id判断所对应的url即可。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

jQuery LigerUI 使用教程表格篇(1)

ligerGrid是ligerui系列插件的核心控件,用户可以快速地创建一个美观,而且功能强大的表格,支持排序、分页、多表头、固定列等等
收藏 0 赞 0 分享

JavaScript中常用的运算符小结

JavaScript中常用的运算符小结,需要的朋友可以参考下。
收藏 0 赞 0 分享

深入理解JavaScript系列(13) This? Yes,this!

在这篇文章里,我们将讨论跟执行上下文直接相关的更多细节。讨论的主题就是this关键字。实践证明,这个主题很难,在不同执行上下文中this的确定经常会发生问题
收藏 0 赞 0 分享

javascript (用setTimeout而非setInterval)

javascript (用setTimeout而非setInterval)如果用setInterval 可能出现 下次调用会在前一次调用前调用
收藏 0 赞 0 分享

JavaScript中两个感叹号的作用说明

用两个感叹号的作用就在于,如果明确设置了o中flag的值(非null/undefined/0""/等值),自然test就会取跟o.flag一样的值;如果没有设置,test就会默认为false,而不是null或undefined
收藏 0 赞 0 分享

javascript写的简单的计算器,内容很多,方法实用,推荐

最近用javascript写了一个简单的计算器,自己测试感觉还好,代码都给了注释,非常不错,推荐大家学习。
收藏 0 赞 0 分享

js的表单操作 简单计算器

javascript写的简单的加减乘除计算器,里面涉及到一些方法还是很实用的哦,新手不要错过
收藏 0 赞 0 分享

Jquery中删除元素的实现代码

empty用来删除指定元素的子元素,remove用来删除元素,或者设定细化条件执行删除
收藏 0 赞 0 分享

javaScript 利用闭包模拟对象的私有属性

JavaScript缺少块级作用域,没有private修饰符,但它具有函数作用域。作用域的好处是内部函数可以访问它们的外部函数的参数和变量(除了this和argument
收藏 0 赞 0 分享

为JavaScript类型增加方法的实现代码(增加功能)

大家在js开发过程中有些功能已经满足不了我们的需求,或没有我们需要的功能,那么我们就可以自己扩展下,个性化js
收藏 0 赞 0 分享
查看更多