zoukankan      html  css  js  c++  java
  • 原生小程序 请求方法的封装及调用

    1.在util.js中写下请求方法

    function request(obj.method, obj.url, obj.data) {
      return new Promise((resolve) => {
        wx.request({
          method: obj.method,
          url: 'http://172.16.12.155:3002/' + obj.url + '.json',
          data: obj.data,
          headers: {
            'Accept': 'application/json; charset=utf-8',
            'X-Requested-With': 'XMLHttpRequest'
          },
          success(res) {
            resolve(res)
          },
          fail(res) {
            console.log(res)
            wx.showToast({
              title: '请求失败',
              icon: 'none',
              duration: 1500
            })
          }
        })
      })
    }
    module.exports = {
      request
    }
    2.在指定的文件中调用
    var utils = require('../../utils/util.js')
    utils.request({
      method: "POST",
      url: "  ",
      data: {
        anchor_pfid: '0'
      }
    }).then(res=>{
      console.log(res)
    });
  • 相关阅读:
    Linux的chattr与lsattr命令详解
    linux mutt邮件发送配置
    linux查看杀死进程
    linux邮件配置
    八-----函数探幽
    一至七-----小东西
    350. Intersection of Two Arrays II
    349. Intersection of Two Arrays
    345. Reverse Vowels of a String
    反转字符串
  • 原文地址:https://www.cnblogs.com/mcll/p/11459083.html
Copyright © 2011-2022 走看看