Giter Site home page Giter Site logo

wx-todo's Introduction

任务发布系统微信小程序端

项目截图

个人页面 todo列表 左滑修改 任务总览

API接口封装

抽取request请求

抽取出来请求之后你可以在内部加一些逻辑判断,比如是否登录,或者收集formId之类的。

const apiRequest = (url, method, data) => {
  var promise = new Promise(function (resolve, reject) {
    wx.request({
      url: domain + url,
      data: data,
      method: method,
      header: {"todo-token": token},
      success: function (res) {
        console.log(res);
        if (res.statusCode === 200) {
           resolve(res.data);
        } else {
          reject({ errormsg: '服务器内部错误,请稍后重试', code: res.statusCode });
        }
      },
      fail: function (res) {
        // 调用接口失败
        reject({ errormsg: '网络错误,请稍后重试', code: 0 });
      }
    })
  });
  return promise;
};

使用

// 引入util
const util = require("../../utils/util.js")

// 获取用户信息
getUserInfo: function(){
util.apiRequest("user/info", "get").then(data => {
  if (data.Code == 200) {
	console.log(data.Data)
  }
})
},

相关项目

wx-todo's People

Contributors

pibigstar avatar

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.