zoukankan      html  css  js  c++  java
  • 小程序常用命令(日常记录)

    1.小程序云函数安装wx-server-sdk命令

      npm install --save wx-server-sdk@latest

    2.在小程序中使用第三方request组件来请求数据(在这里通过云函数来调用第三方组件,组件地址:https://github.com/request/request-promise

      首先新建一个云函数,然后右键选择在终端打开,输入一下命令:

      npm install --save request

      npm install --save request-promise

      然后在云函数中定义如下代码:

      // 云函数入口文件
      const cloud = require('wx-server-sdk')
      //在这里引入request-promise组件
      var rp = require('request-promise');
      cloud.init()
      // 云函数入口函数
      exports.main = async (event, context) => {
        //这里的接口是请求一个电影数据列表,需要传入从第几页开始以及每页的个数
        return rp(`http://t.yushu.im/v2/movie/top250?start=${event.start}&count=${event.count}`)
          .then(function (res) {
            return res
          })
          .catch(function (err) {
            console.error(err)
          });
      }
      //最后在需要渲染电影列表的地方使用改云函数,代码如下:
      wx.cloud.callFunction({
        //云函数的名称movielist
        name: 'movielist',
        //接口需要的参数(从第几页开始以及每页多少条数据)
        data: {
          start: this.data.movielist.length,
          count: 6
        }
      }).then(res => {
        //这里将返回的数据赋值给本页面的data,便于在页面中渲染页面使用
        this.setData({
          movielist: this.data.movielist.concat(JSON.parse(res.result).subjects)
        });
      }).catch(err => {
        console.error(err);
      })
      到此就是request组件的使用介绍
  • 相关阅读:
    SqlServer存储过程
    SQL Server :DBLINK创建及使用
    jQuery控制TR的显示隐藏
    JAVA------22.git导出项目,启动项目
    JAVA------21.String转时间,并向前推进一天
    JAVA------20.经纬度转换省市区
    JAVA------20.图片中插文字和图片
    JAVA------19.生成二维码并插入logo
    JAVA------18.excel导出
    JAVA------17.charles(青花瓷)抓包工具,适用安卓
  • 原文地址:https://www.cnblogs.com/shenwh/p/11118496.html
Copyright © 2011-2022 走看看