国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序前端promise封裝代碼實例

2024-07-22 01:17:39
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了微信小程序前端promise封裝代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

代碼如下

config.js

const config = {   base_url_api : "https://douban.uieee.com/v2/movie/",}export {config}

http.js

import { config } from "../config";class HTTP {  requset({ url, method = "GET", data = {} }) {    const promise = new Promise((resolve, reject) => {      wx.request({        url: config.base_url_api + url,        data,        method,        header: {          'Content-Type': 'json'        },        success: res => {          //狀態碼 toString() 轉成字符串          const statusCode = res.statusCode.toString();          if (statusCode.startsWith("2")) {            resolve(res.data)          } else {            this._show_error();          }        },        fail: res => {          reject(err);          this._show_error();        }      })    })    return promise;  }  _show_error() {    wx.showToast({      title: '網絡錯誤',      icon: 'none'    })  }}export { HTTP }

model/movie.js

import {HTTP} from "../utils/http";class MovieModel extends HTTP{  getInTheaters(){    return this.requset({      url:"in_theaters"    })  }  getTop250(){    return this.requset({      url:"top250"    })  }  getComingSoon(){    return this.requset({      url:"coming_soon"    })  }}export {MovieModel};

pages/index/index.js

const app = getApp();import {MovieModel} from "../../model/movie";const movieModel = new MovieModel();Page({ onLoad(){  // movieModel.getInTheaters().then(res=>{  //  console.log(res)  // })  const inTheaters = movieModel.getInTheaters()  const top250 = movieModel.getTop250();  const comingSoon = movieModel.getComingSoon();  Promise.all([inTheaters,top250,comingSoon]).then(res=>{   let[inTheaters,top250,comingSoon] = res;   console.log(inTheaters)  }) }})

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平山县| 当雄县| 英超| 贵州省| 乳山市| 资源县| 沂源县| 正镶白旗| 高碑店市| 福泉市| 广东省| 天气| 博客| 绍兴县| 郑州市| 江城| 垣曲县| 图片| 定边县| 秭归县| 南郑县| 南丹县| 灵宝市| 苏尼特右旗| 泗阳县| 清苑县| 仙桃市| 九寨沟县| 巫山县| 云龙县| 东乌珠穆沁旗| 兴宁市| 香港 | 香港| 重庆市| 阿拉善右旗| 资源县| 棋牌| 万载县| 兴海县| 团风县|