微信小程序 阶段总结

2021-03-07  本文已影响0人  Vector_Wan

标签(组件)

事件

API

    wx.navigateTo({
      url: 'url',
    })
  getUserName: function () {
    wx.openSetting({})
    var that = this;
    // 调用微信的接口获取当前用户的信息(传递的参数是字典)
    wx.getUserInfo({
      // 调用成功后触发(回调函数)
      success: function(res) {
        console.log("成功:", res);
        // 修改页面和后台数据
        that.setData({name: res.userInfo.nickName});
        that.setData({path: res.userInfo.avatarUrl})
      },
      // 调用失败后触发
      fall: function (res) {
        console.log("失败:", res);
      }

    });
  },
  getLocalpath: function () {
    var that = this;
    wx.chooseLocation({
      success: function (res) {
        // console.log(res);
        that.setData({localpath: res.name})
      }
    });
  }
  uploadPics: function () {
    var that = this
    wx.chooseImage({
      count: 9,
      sizeType: "original",
      sourceType: ['album', 'camera'],
      success: function (res) {
        // 成功的回调函数
        console.log(res);
        that.setData({imageList: that.data.imageList.concat(res.tempFilePaths)})
        
      },
      fail: function (res){
        // 失败的回调函数
      },
      complete: function (res) {
        // 成功 or 失败的回调
      }
    })
  },

数据绑定

this.setData({})
注意 this 和 that

for 指令

wx-for

上一篇 下一篇

猜你喜欢

热点阅读