微信小程序开发过程中总结

 

1.连接口

在项目的app.js文件下定义接口地址

微信小程序开发过程中总结

右上角详情-勾选

微信小程序开发过程中总结

使用

const app = getApp();

 

wx.request({

      url: app.globalData.targetIP + "/user/showMyCommonReserve",

      data: {

        co_eeid: that.data.ee_id,

        begin_num:0

      },

      header: {

        'content-type': 'application/x-www-form-urlencoded'

      },

      method: "POST",

      success(res) {

    

      },

      fail: function (err) {

        console.log("请求失败");

      }

    })

2.跳转页面

      wx.navigateTo({

        url: '/pages/personal/editProfile/editProfile?ee_id=' + wx.getStorageSync('userInfo').ee_id

      });

可以navigateBack

 

Wx.redirect不可以

3.生命周期函数

Onload

/**

   * 生命周期函数--监听页面加载

   * 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取打开当前页面路径中的参数。

   */

  onLoad: function (options) {

console.log(options);

    var that = this;

    this.setData({

      ee_id: options.ee_id

    })

  },

 

Onshow

 

  /**

   * 生命周期函数--监听页面显示—最常用

   */

  onShow: function () {

var that=this;//必须有

 

onUnload

 /**

   * 生命周期函数--监听页面卸载

   */

  onUnload: function () {

    var that=this;

    wx.request({//提交修改后的信息

      type: "POST",

      url: app.globalData.targetIP + "/user/updateEmployeeInfo",

      data: {

        ee_id: that.data.userInfo.ee_id,

        ee_photo: that.data.photo,/**that.data.userInfo.ee_photo,*/

        ee_phone: that.data.userInfo.ee_phone,

        ee_email: that.data.userInfo.ee_email

      },

      success: function (response) {

        setTimeout(function () {

          wx.navigateBack({

            delta: 1

          })

        }, 3000)

      },

      error: function (jqXHR) {

        console.log('修改失败');

      }

    });

  },

 

onhide

/**

   * 生命周期函数--监听页面隐藏

   */

  onHide: function () {

    that.setData({

      bm_id: '',

      fr_problem: ''/**设备故障描述 */,

      equipmentId: ''/**保修过的设备id */,

      allEquipment: ''/**所有设备列表id */,

      allEquipmentName: '',/**所有设备名字 */

      equipmentStyle: '',

      deviceList: ''/**存储报修设备 */,

      display: '',

      deviceListName: '',/**存储保修设备姓名 */

      problem: ''/**我填写的故障 */

    })

    deviceList=[];

    deviceListName=[];

  },

4.本地存储

wx.setStorageSync('userInfo', res.data.data);//存储个人信息在本地

5.提示

      wx.showToast({

        title: '原密码格式错误',

        icon:'none',/**小程序只有两种icon:success\loading设置none可以不显示icon也可以在后面用image:'本地图片路径'来换自定义icon*/

        duration: 3000

      })

6.上传照片

  upload:function(e){

    var that=this;

    wx.chooseImage({

      count: 3,

      sizeType: ['original', 'compressed'],

      sourceType: ['album', 'camera'],

      success(res) {

        // tempFilePath可以作为img标签的src属性显示图片

        const tempFilePaths = res.tempFilePaths;

        console.log(tempFilePaths);

        for(var m=0;m<tempFilePaths.length;m++){

          tempArr.push(tempFilePaths[m]);

        }

        that.setData({

          imageList:tempArr//图片地址可以得到

        });

      }

    })

  },

7.小点

that.data.imageList.splice(index,1);//可以不重新set一次,则imageList值改变,但不会动态重新渲染到页面上,必须重新set

    that.setData({

      imageList:that.data.imageList

})

8.延时

        setTimeout(function(){//设置提示信息后再跳转

          wx.navigateBack({

            delta: 1

          })

        },3000);