美文网首页
微信小程序

微信小程序

作者: Sharise_Mo佩珊 | 来源:发表于2017-10-16 14:21 被阅读0次

组件使用问题

1、scroll-view滚动到指定位置:用到scroll-view的scroll-into-view属性
使用场景:

  • 按字母顺序滚动
  • 聊天框最新聊天信息在底部

http://blog.csdn.net/zhaoyazhi2129/article/details/53787695
2、动态类名绑定

<view wx:for="{{labelList}}" class="label-item {{item.isActive?'label-active' : '' }}">{{item.name}}</view>

3、分享图片
https://mp.weixin.qq.com/debug/wxadoc/dev/api/share.html#onshareappmessageoptions

image.png

4、页面传参

 <navigator url="/pages/order/order-detail/index?id={{item.id}}" class="flex title-box"></navigator>

5、生成二维码:http://blog.csdn.net/wtdask/article/details/73776356
6、小程序开卡组件: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1499332673_Unm7V
7、switchTab跳转之后页面不刷新

wx.switchTab({ 
  url: '../index/index', 
  success: function (e) { 
    var page = getCurrentPages().pop(); 
    if (page == undefined || page == null) return; 
    page.onLoad(); 
  } 
}) 

8、动态设置tabbar
https://mp.weixin.qq.com/debug/wxadoc/dev/api/ui-tabbar.html#wxsettabbarstyleobject
API--界面--设置tabbar

image.png

工具问题

1、0.17版本的wx.request()会发不出请求,需要改成0.22版本的就好了

2、善用工具
一个小程序的组件化开发工具wepy
wepy: https://segmentfault.com/a/1190000007580866
github:https://github.com/Tencent/wepy

image.png
image.png

API调用问题

  • wx.getUserInfo(): 能调起授权确认弹窗
  • wx.login(): 调用wx.login()获取登录凭证(code),用code调用服务器后台API换取用户登录态信息,openid,session_key,union_id 【调用login会引起登录态的刷新,之前的sessionKey会失效】
  • wx.request():发起请求
  • wx.checkSession():检查当前用户的登录状态是否有效
wx.checkSession({
  success: function(){
    //session 未过期,并且在本生命周期一直有效
  },
  fail: function(){
    //登录态过期
    wx.login() //重新登录
    ....
  }
})
  • 登录态的维护:


    image.png

引用外部资源:js和wxss

js

// format.js
const formatTime = ()=>{}
module.exports = {
  formatTime: formatTime
}

// index.js 引入
const format = require('../../utils/format)
//使用
format.formatTime()

wxss

// index.wxss
@import '../../common.wxss'

相关文章

网友评论

      本文标题:微信小程序

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