zoukankan      html  css  js  c++  java
  • 微信小程序的新的

    app.request.get('http://ele.kassing.cn/v1/pois',this.data.city).then(res=>{
          console.log(res)
          this.setData({
            addr:res.data
          })
        }),

    在app.js中定义全局方法

      request: {
        get(url, data = {}) {
          return new Promise((resolve, reject) => {
            // 进行请求
            wx.request({
              url,
              data,
              success: (res) => {
                resolve(res)
              },
              fail(err) {
                reject(err)
              }
            })
          })
        },
        post(url, data = {}) {
          return new Promise((resolve, reject) => {
            wx.request({
              url,
              data,
              method: "POST",
              success: res => {
                resolve(res)
              },
              fail: (err) => {
                reject(err)
              }
            })
          })
        }
      }

     如果在某一个页面需要使用全局的方法,只需要在页面顶部添加代码

    const app=getApp();

     正常使用的时候为

    app.request.get('http://ele.kassing.cn/v1/pois',this.data.city).then(res=>{
          console.log(res)
          this.setData({
            addr:res.data
          })
        }),
    希望自己写的东西能够对大家有所帮助!谢谢
  • 相关阅读:
    15回文相关问题
    14海量日志提取出现次数最多的IP
    13概率问题
    12胜者树和败者树

    pysnmp程序
    python 多线程 生产者消费者
    python多线程
    pysnmp使用
    PyYAML使用
  • 原文地址:https://www.cnblogs.com/mrxinxin/p/10284289.html
Copyright © 2011-2022 走看看