微信小程序 测试用例引用本地js的json data 数据

    技术2023-10-27  99

    1、question-data.js

    var local_question = [... ]

    module.exports = {    //数据暴露出去     questions: local_question } 2、数据绑定post.js

      var questionData=require('../../data/question-data.js');  //引入   data: {  //小程序总是会读取data对来做数据绑定,这个动作我们称为            //动作a,而这个动作A是在load事件执行之后发生的    },   /**    * 生命周期函数--监听页面加载 页面初始化  on开头的函数监听函数    */   onLoad: function (options) {     this.setData({questions:questionData.questions});  //如果是异步操作赋值那么必须用this.setData   }, 3、显示post.wxml

    <block wx:for="{{questions}}"  wx:for-item="item">    <view class='post-container'>     <view class='post-author-date'>         <image src='{{item.avatar}}'></image>         <text>{{item.name}}</text>     </view>     <text class='post-title'>{{item.title}}</text>     <image class='post-image' src='{{item.imgSrc}}'></image>     <text class='post-content'>{{item.content}}</text>     <view class='post-like'>         <image class='view' src='/images/view.png'></image>         <text class='view-txt'>92</text>         <image class='collect' src='/images/star.jpg'></image>         <text class='collect-txt'>65</text>     </view>    </view>   </block> 

    Processed: 0.014, SQL: 9