美文网首页
微信小程序 阶段总结

微信小程序 阶段总结

作者: Vector_Wan | 来源:发表于2021-03-07 13:41 被阅读0次

标签(组件)

  • text
  • view
  • image
  • navigator 跳转到其他页面(非tabbar页面) 想一下怎么传递参数
  • button 按钮(获取用户信息时建议使用)

事件

  • bindtap 点击事件
    想一下如何绑定点击事件,怎么写响应函数

API

  • wx.navigatTo js 中的页面跳转
    wx.navigateTo({
      url: 'url',
    })
  • wx.openSetting 手动设置授权信息
  • wx.getUserInfo 获取用户信息 (结合 button 按钮)
  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);
      }

    });
  },
  • wx.chooseLocation 获取地理位置信息
  getLocalpath: function () {
    var that = this;
    wx.chooseLocation({
      success: function (res) {
        // console.log(res);
        that.setData({localpath: res.name})
      }
    });
  }
  • wx.chooseImage 用户上传图片
  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

相关文章

网友评论

      本文标题:微信小程序 阶段总结

      本文链接:https://www.haomeiwen.com/subject/lotyqltx.html