Awesome Open Source
Awesome Open Source

luch-request

npm npm github github stars github forks

  • Promise request
  • /
  • task
  • uni.request

npm
npm i luch-request -S

npm

github

github npm run build DCloud/luch-request

DCloud:

DCloud

Example

import Request from '@/utils/luch-request/index.js' // 
// import Request from 'luch-request' // npm

const http = new Request();

GET

http.get('/user/login', {params: {userName: 'name', password: '123456'}}).then(res => {

}).catch(err => {

})
// 
http.get('/user/login', {
    params: {userName: 'name', password: '123456'}, /* url */
    header: {}, /* header */
    dataType: 'json',
    // customcustomObject.assign()
    custom: {auth: true}, // authtruetoken
    // #ifndef MP-ALIPAY
    responseType: 'text',
    // #endif
    // #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
    timeout: 60000, // H5(HBuilderX 2.9.9+)APP(HBuilderX 2.9.9+)2.10.0
    // #endif
    // #ifdef APP-PLUS
    sslVerify: true, //  ssl  5+AppHBuilderX 2.3.3+
    // #endif
    // #ifdef H5
    withCredentials: false, // cookiesH5HBuilderX 2.6.15+
    // #endif
    // task, optionsoptions
    getTask: (task, options) => {
         // setTimeout(() => {
         //   task.abort()
         // }, 500)
    },
    // statusCode
    validateStatus: function validateStatus(statusCode) {
       return statusCode >= 200 && statusCode < 300
    }
}).then(res => {

}).catch(err => {

})

POST

http.post('/user/login', {userName: 'name', password: '123456'} ).then(res => {

}).catch(err => {

})
// 
http.post('/user/login', {userName: 'name', password: '123456'}, {
    params: {}, /* url */
    header: {}, /* header */
    dataType: 'json',
    // customcustomObject.assign()
    custom: {auth: true}, // authtruetoken
    // #ifndef MP-ALIPAY
    responseType: 'text',
    // #endif
    // #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN
    timeout: 60000, // H5(HBuilderX 2.9.9+)APP(HBuilderX 2.9.9+)2.10.0
    // #endif
    // #ifdef APP-PLUS
    sslVerify: true, //  ssl  5+AppHBuilderX 2.3.3+
    // #endif
    // #ifdef H5
    withCredentials: false, // cookiesH5HBuilderX 2.6.15+
    // #endif
    // task, optionsoptions
    getTask: (task, options) => {
         // setTimeout(() => {
         //   task.abort()
         // }, 500)
    },
     // statusCode
     validateStatus: function validateStatus(statusCode) {
        return statusCode >= 200 && statusCode < 300
     }
}).then(res => {

}).catch(err => {

})

upload

  http.upload('api/upload/img', {
    params: {}, /* url */
    // #ifdef APP-PLUS || H5
    files: [], //  files filePath  name AppH5 2.6.15+
    // #endif
    // #ifdef MP-ALIPAY
    fileType: 'image/video/audio', // 
    // #endif
    filePath: '', // 
    // customcustomObject.assign()
    custom: {auth: true}, // authtruetoken
    name: 'file', //  key ,  key 
    // #ifdef H5 || APP-PLUS
    timeout: 60000, // H5(HBuilderX 2.9.9+)APP(HBuilderX 2.9.9+)
    // #endif
    header: {},  /* header */
    formData: {}, // HTTP  form data
    // task, optionsoptions
    getTask: (task, options) => {
      // task.onProgressUpdate((res) => {
      //   console.log('' + res.progress);
      //   console.log('' + res.totalBytesSent);
      //   console.log('' + res.totalBytesExpectedToSend);
      //
      //   // 
      //   if (res.progress > 50) {
      //     uploadTask.abort();
      //   }
      // });
    }
  }).then(res => {
    // res.data JSON.parse
  }).catch(err => {

  })

luch-request Guide

luch-request
github


vue-admin-beautiful

vue-admin-beautiful vue/cli 4

vue-admin-beautiful

uView

uView


    • postoptionRequest Method
  1. post
    • uni-request
      uni-request api dataObject/String/ArrayBuffer 0.0
  2. TypeError: undefined is not an object (evaluating 'this.$http.get')
    • export default export
    • import { http } from '@/utils/luch-request/index.js'
  3. setConfig request
    • setConfig /header token
    • interceptors.request setConfig setConfig

tip

  • nvue
  • hbuilderx beat-3.0.4 alpha-3.0.4
  • npm
  • license: MIT

issue


  • lei 0.0
  • uni-app requestclassaxiosapirequestaxiosrequest2019-05
<a href="https://ext.dcloud.net.cn/plugin?id=392">luch-request</a>
  1. Google
  2. xxissue
  3. bug,issue,
  1. app iosandroid
  2. 'issue'
  3. QQ:370306150


wechat

Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,060,209
Vue (66,023
Github (43,830
Request (28,793
Admin (21,959
Promise (10,877
Wechat (4,251
Vue Admin (406
Github Stars (260
Uni App (236
Uni (35
Dcloud (15