posts-data.js
var local_database = [
{
date: 'sep 18 2016',
title: '正是虾肥蟹壮时',
imgSrc: '/images/post/crab.png',
avatar: '/images/avatar/1.png',
content: '本文档将带你一步步创建完成一个微信小程序,并可以在手机上体验该小程序的实际效果。这个小程序的首页将会显示欢迎语以及当前用户的微信头像,点击头像',
reading: '112',
collection: '96'
},
{
date: 'sep 18 2016',
title: '正是虾肥蟹壮时',
imgSrc: '/images/post/crab.png',
avatar: '/images/avatar/1.png',
content: '本文档将带你一步步创建完成一个微信小程序,并可以在手机上体验该小程序的实际效果。这个小程序的首页将会显示欢迎语以及当前用户的微信头像,点击头像',
reading: '112',
collection: '96'
}];
//暴露变量,这样才可以使用
module.exports = {
postList: local_database
}
post.js中
var postData = require("../../data/posts-data.js")
Page({
data: {
},
onLoad: function (options) {
//取出postList变量
//赋值给data里面的postList
this.setData({
postList: postData.postList
})
console.log("onLoad")
}
})
现在使用
this.data.postList = postData.postList
设置data数据不管用了