请教一下老师为何新闻列表一直不显示

来源:18-2 使用require方法加载js模块儿文件

慕仰7034662

2019-04-29

//posts.wxml代码

<import src="post-item/post-item-template.wxml" />
<view>
  <swiper indicator-dots='true' interval='2000' autoplay='true'>
    <swiper-item>
      <image src='/images/1.png'></image>
    </swiper-item>
    <swiper-item>
      <image src='/images/2.png'></image>
    </swiper-item>
    <swiper-item>
      <image src='/images/3.png'></image>
    </swiper-item>
    <swiper-item>
      <image src='/images/4.png'></image>
    </swiper-item>
  </swiper>
 <block wx:for="{{postList}}" wx:for-item="item"  wx:for-index="">
    <template is="postItem" data="{{item}}" />
  </block>
</view>
//posts.js代码

var postsData = require("../../data/posts-data.js")
Page({

  data:{
  
  },
  onLoad: function () {
    
    this.data.postList = postsData.postList
    // this.setData({
    //   posts_key: postsData.postList
    //   })

  }
})
//post-item-template.wxml代码

<template name="postItem">
<view class='post-container'>
    <view class='post-author-date'>
      <image class='post-author' src='{{item.author_img}}'></image>
      <text class='post-date'>{{item.date}}</text>
    </view>
    <text class='post-title'>{{item.title}}</text>
    <image class='post-image' src='{{item.post_img}}'></image>
    <text class='post-content'>{{item.content}}</text>
    <view class='post-like'>
      <image class='post-like-image' src='{{item.collect_img}}'></image>
      <text class='post-like-font'>{{item.collect_num}}</text>
      <image class='post-like-image' src='{{item.view_img}}'></image>
      <text class='post-like-font'>{{item.view_num}}</text>
    </view>
  </view>
  </template>
//app.json代码

{
  "pages": [
    "pages/welcome/welcome",
    "pages/posts/posts"
  ],
  "window": {
    "navigationBarBackgroundColor": "#b3d4db"
  },
  "sitemapLocation": "sitemap.json"
}
//posts-data.js代码

var post_content = [{
  date: "2019 4 27",
  title: "正是虾肥蟹壮时",
  post_img: "/images/post/crab.png",
  content: "橘黄蟹正肥,品尝秋之味",
  view_num: "112",
  collect_num: "99",
  author_img: "/images/avatar/1.png",
  view_img: "/images/icon/view.png",
  collect_img: "/images/icon/chat.png"
},
{
  date: "2019 4 27",
  title: "正是虾肥蟹壮时",
  post_img: "/images/post/crab.png",
  content: "橘黄蟹正肥,品尝秋之味",
  view_num: "112",
  collect_num: "99",
  author_img: "/images/avatar/1.png",
  view_img: "/images/icon/view.png",
  collect_img: "/images/icon/chat.png"
},
{
  date: "2019 4 27",
  title: "正是虾肥蟹壮时",
  post_img: "/images/post/crab.png",
  content: "橘黄蟹正肥,品尝秋之味",
  view_num: "112",
  collect_num: "99",
  author_img: "/images/avatar/1.png",
  view_img: "/images/icon/view.png",
  collect_img: "/images/icon/chat.png"
}]
module.export = {
  postList: post_content
}
写回答

2回答

JIANGYUHANG

2019-06-20

你可以试试把wx:for里边的内容改成pots_key然后在运行一下有没有效果

0
0

7七月

2019-04-30

这看不出来的,需要调试啊,我也只能调试才能找到问题。试着调试下吧,早晚要学会调试。

0
0

微信小程序入门与实战(全新版) 超20000人学习的好课

4年同步微信官方迭代,累计20000+人学习, 比微信官方更火爆!

23976 学习 · 6933 问题

查看课程