小程序的js处理步骤

<!-- 包含请求路由 -->
var hostUrl = require('../../config.js').hostUrl;
Page({
<!-- 页面的初始数据 -->

data: { <!-- 定义空数组用于收集所有的数据 --> GetData: [], foot: [], userinfo: { avatarUrl: '/images/logo.png', nickName: "兜兜转转" }, }, <!-- 页面加载函数 --> onLoad: function(options) { var that = this; <!-- 获取值(setData方法获取到的值会自动保存进data中) --> that.setData({ <!-- getStorageSync()方法获取本地存储的值 --> <!-- uid: wx.getStorageSync('uid'), --> uid: '474', }) console.log('==========='); console.log(that.data.uid); <!-- 在加载函数中发送数据请求 --> wx.request({ <!-- 请求的服务器地址 --> url: hostUrl + 'myMsg', data: { <!--请求的数据 --> uid: that.data.uid, }, <!-- 成功后的回调函数 --> success(res) { that.setData({ <!-- 将返回的结果放入到之前定义的空数组中 --> GetData:res.info, }) <!-- 判断与执行 --> console.log(that.data.GetData) }, <!-- 失败后的回调 --> fail(res) { console.log("请求无响应") } }) } })

 

posted @ 2018-12-17 17:04  WQ兜兜转转  阅读(590)  评论(0编辑  收藏  举报