欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

微信小程序的探討--與外站進(jìn)行數(shù)據(jù)傳輸、前后端交互 - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們在追求其視覺表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏壧峁┍憬莸闹С郑?

您當(dāng)前位置>首頁 » 新聞資訊 » 小程序相關(guān) >

微信小程序的探討--與外站進(jìn)行數(shù)據(jù)傳輸、前后端交互

發(fā)表時(shí)間:2021-4-30

發(fā)布人:葵宇科技

瀏覽次數(shù):90

與外站進(jìn)行數(shù)據(jù)傳輸

    <view class="bt-ok" bindtap="okClick">確定提交</view>
  • 1

Page({
//確認(rèn)提交
  okClick: function () {

  var that = this;//此處必須重定義,才能在回調(diào)函數(shù)里使用
      wx.request({   //發(fā)起url請求
        url: 'http://wq.ycwjwl.com/json.php',
        method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        data: {  //傳遞參數(shù)
          x: 'df so handsome',
          y: '2'
        },
        header: {   //請求方式
          'content-type': 'application/x-www-form-urlencoded'   //post must be this
           //'content-type': 'application/json'     //this for get
        },
        success: function (res) {       //訪問成功之后的返回值     return  data、statusCode、header 
          console.log(res);
         var r = res.data.x;      //獲取json參數(shù)里的x的值
          that.setData({   //異步傳輸數(shù)據(jù)到前端
            toastHidden: false,
            toastTxt: "提交成功",
            rt: r
          });         
        }
      })
      console.log("log:"+this.data.rt);
     }
  })
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

前后端交互

Page({
 data: {//頁面初始數(shù)據(jù)
    orderList: [],
    total: 0, //總價(jià)格   
  },
 onLoad: function(options) {  //自帶的事件   [說明](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/app-service/page.html)
    // Do some initialize when page load.
  },
    //自定義函數(shù)
 returnClick: function () {
    wx.navigateBack();
  },
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
 <view class="cost">總價(jià):<span>{{total}}</span></view>
 <view class="bt-return" bindtap="returnClick">返回修改</view>

<view class="orderlist" wx:for="{{orderList}}" wx:key="item.id">     //遍歷一個(gè)數(shù)組
      <span>{{item.title}}</span><span style="float:right;">{{item.cost}} * {{item.num}}</span>
    </view>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

頁面之間傳值

//home
Page({
//提交訂單

  sublimitClick: function (e) {


     var agrs = JSON.stringify(this.data.orderList);//將json數(shù)組轉(zhuǎn)化為get參數(shù)
    wx.navigateTo({
      url: '../order/order?order=' + agrs
    })
  },
})
//order
Page({
// 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
  onLoad: function (options) {

    //object 轉(zhuǎn) array
    var order = JSON.parse(options.order);  //將get到的json字符串轉(zhuǎn)化為json數(shù)組
    var t_order = [];
    var t_total = 0;
    for (var k in order) {
      if (order[k].num > 0) {
        t_order.push(order[k]);
        t_total = t_total + order[k].cost * order[k].num; //計(jì)算總價(jià)格
      }
    }

    this.setData({  //與前端進(jìn)行交互
      orderList: t_order,
      total: t_total
    });

  },
  })
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

相關(guān)案例查看更多