微信小程序生成详情内容页 Thinkphp后台调用数据库

书接上一篇文章  微信小程序生成列表页带分页功能 Thinkphp后台调用数据库,今天说下内容页面:

列表页链接加上产品ID,如下:

<navigator url="../goods/goods?goods_id={{item.goods_id}}" ></navigator>

wxml页面: 

<!--pages/goods/goods.wxml-->
<scroll-view scroll-y="true">
  <view class="meta">
    <image class="poster" mode="aspectFit" src="{{imgurl}}{{goods.goods_big_img}}" ></image>
    <text class="title">{{goods.goods_name}}</text>
    <text class="info">价格:{{goods.goods_price}}</text>
    <text class="info">数量:{{goods.goods_number}}</text>
    <text class="info">时间:{{goods.goods_create_time}}</text>
  </view>
  <view class="summary">
    <text class="label">商品描述:</text>
    <text class="content">{{goods.goods_introduce}}</text>
  </view>
</scroll-view>

js页面:

// pages/goods/goods.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: "https://cs.xxxxxx.com/shop/",
    goods: []
  },

  
  /**
   * 生命周期函数--监听页面加载  goods_id: params.goods_id
   */
  onLoad: function (params) {
    wx.showToast({
      title: "加载中..",
      icon: "loading",
      duration: 10000
    });
    var that = this;
    console.log(params);
    wx.request({
      url: "https://cs.xxxxxx.com/shop/index.php/Home/Goods/detailjson/goods_id/" + params.goods_id,
      data: {},
      header: {
        'content-type': 'json' // 默认值
      },
      success: function (res) {
       // console.log(res.data.info);
        wx.hideToast();
        that.setData({
          goods: res.data.info
        })
      },
     
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

wxss页面(随便写的可以忽略):

/* pages/goods/goods.wxss */
.meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 500rpx;
  padding: 50rpx 40rpx;
}
.title {
  font-size: 34rpx;
  color: #444;
}

.info {
  font-size: 30rpx;
  color: #666;
  margin-top: 20rpx;
  width: 80%;
}

.summary {
  width: 80%;
  margin: 30rpx auto;
}

.label {
  display: block;
}

.content {
  color: #666;
  font-size: 20rpx;
  padding: 10rpx
}

Thinkphp后台(3.2.3):

public function detailjson(){
			
			S(array('prefix'=>('detailjson'.I('goods_id'))));
			if(!S('detailjson')){
			$goods = D('Goods');
			$info = $goods -> find(I('goods_id'));

			$data['info']=$info;
			S('detailjson',$data,300);//300秒  5分
			dump($this->ajaxReturn($data,'json'));
			exit;
			}else{
				dump($this->ajaxReturn(S('detailjson')));
			exit;
				
			}
			
		}

结束!

类似这样的(磕碜点.. 哈哈哈):

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值