Giter VIP home page Giter VIP logo

wechat_clouddb_demo's Introduction

wechat_cloudDB_demo

这是微信小程序·云数据库开发的demo,其中包含三个页面:

  • pages/course/course:课程列表,支持分页加载
  • pages/lesson/lesson:课件列表,支持分页加载
  • pages/video/video:用来播放视频课件的页面

借助于提供的云数据库,可以实现非API方式来动态加载内容。后续只需要直接云端数据库的数据,就能动态查看不同的课程以及课件。

/**
   * 获取课程信息
   */
  getCourses: function () {
    wx.cloud.database().collection("course")
      .skip(this.biz_data.page_index * CONFIG.PAGE_SIZE)
      .limit(CONFIG.PAGE_SIZE)
      .get()
      .then(res => {
        this.biz_data.loading_more = false;
        if (res.data.length < CONFIG.PAGE_SIZE) {
          this.data.footer.no_more = true;
        } else {
          this.data.footer.need_footer = true;
        }
        if (res.data.length == 0) {
          // 空数组说明无需刷新列表内容,只需刷新footer
          this.setData({
            footer: {
              need_footer: this.data.footer.need_footer,
              no_more: this.data.footer.no_more,
            }
          });
        } else {
          this.setData({
            courses: this.data.courses.concat(res.data),
            footer: {
              need_footer: this.data.footer.need_footer,
              no_more: this.data.footer.no_more
            }
          })
        }
      })
      .catch(err => {
        console.error(err)
      });
  }

注意事项

  • 创建项目时,后端服务选择『小程序·云开发』

  • 更换config.js里云环境的值为你自己的

    function getCloudEnv () {
      if (getEnv() == "pro") {
        return "pro-xxx";
      } else {
        return "pro-yyy";
      }
    }
  • 如果遇到以下报错信息,请将基础库调整为2.3.0及以上版本

    -401002 api parameter error | errMsg: parameter offset of function skip must be provided

参考文档

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.