微信小程序开发流程和注意事项

1:微信小程序开发 需要申请小程序appid,没有此id无法进行发布和登陆。访问地址(https://mp.weixin.qq.com/cgi-bin/registermidpage?action=index&lang=zh_CN


3:下载开发者工具 访问地址https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/devtools.html(过于简单不在详细介绍
二:开发过中的注意事项
1:发布需要绑定域名,不绑定域名会报错(开发过程中可用开发者工具模拟,不需要域名也可以,)
2:页面用户信息页面间传递;
app.js获取信息,并且绑定到globalData
// 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo
              // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
其他页面调用 用户信息
const app = getApp()
onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
3:页面跳转的区别 navigateTo 和 redirectTo
wx.navigateTo({

url: 'page/detail/detail?product_id=222'  
})
 
wx.redirectTo({

url: 'page/home/home?user_id=111'
})
 
navigateTo跳转后可以从导航进行返回,相当于navigateTo,打开了一个新页面,老页面没有关闭。
redirectTo跳转后无法进行返回,相当于页面重定向。

4:页面跳转的传值方式
(1) 页面跳转函数:
wx.navigateTo({
url: '../queryResult/queryResult?queryBean=' + queryBean,    
})

新页面接受参数:onLoad: function (options) {    
var that=this    
var queryBean = JSON.parse(options.queryBean);    
that.setData({      queryBean: queryBean    })    
}

(2)可用存储方式来传递

wx.setStorage({
  key: "key" ,
})

wx.getStorageSync('key')来获取存储方式


 
 


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值