轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 微信小程序 查看主题

小技巧四则: 点击空白处隐藏input,下拉刷新,全局变量

发布者: jtac | 发布时间: 2018-2-25 14:57| 查看数: 6029| 评论数: 1|帖子模式

一:点击空白处隐藏input,点击评论出现

wxml:

  1. <scroll-view style="height: {{windowHeight}}px; width: {{windowWidth}}px;" scroll-y="true" bindscrolltoupper="pullDownRefresh" bindscrolltolower="pullUpLoad" bindtap="click_blank">
  2. <view wx:if="{{comment}}" class="comment-input"><input type="text" name="content" auto-focus placeholder-style="margin-top:-8rpx;" placeholder="{{comment_placeholder}}" bindchange="comment_input" /><button>发送</button></view>

js:

  1. // 评论(点击空白处隐藏input,点击评论出现)
  2. click_blank:function(e){
  3. var flag = "";
  4. var comment_placeholder ="";
  5. if(e.target.dataset.comment==1){
  6. flag = true;
  7. comment_placeholder = e.target.dataset.username;
  8. }else{
  9. flag = false;
  10. comment_placeholder = "";
  11. }
  12. this.setData({
  13. comment:flag,
  14. comment_placeholder:"评论"+comment_placeholder+"动态"
  15. })
  16. },

二:下拉刷新

wxml:

  1. <view wx:if="{{items}}">
  2. <scroll-view scroll-y="true" bindscrolltoupper="upper" bindscrolltolower="lower" style="height: {{windowHeight}}px">
  3. <view wx:for="{{items}}">
  4. <view class="item">
  5. <view class="item-top">
  6. <view class="avatar" wx:if="{{item.avatar}}">
  7. <image mode="aspectFill" src="{{'}}"></image>
  8. </view>
  9. <view class="avatar" wx:else><image mode="aspectFill" src="../img/default_img.png"></image></view>
  10. <view class="item-username">
  11. <text>{{item.username}}{{item.jobname}}</text>
  12. </view>
  13. <view class="item-time">{{item.adddate}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view wx:if="{{hasMore}}">
  18. <view wx:if="{{nomore}}" class="tips">
  19. <text>没有更多内容了</text>
  20. </view>
  21. <view wx:else class="tips">
  22. <image src="../img/loading.gif" mode="aspectFill"/>
  23. <text>玩了命的加载中...</text>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. <loading hidden="{{loading}}">加载中...</loading>

js:

  1. Page({
  2. data: {
  3. windowHeight:"",//屏幕高
  4. page:1,
  5. totalPage:"",//总页数
  6. nomore:false,//加载完所有信息显示
  7. hasMore:true//加载时显示
  8. },
  9. // 加载
  10. onLoad: function (e) {
  11. console.log(this.data.page);
  12. this.getDataFromServer(this.data.page);
  13. },
  14. // 读取屏幕高度,赋值给scroll-view
  15. onShow: function( e ) {
  16. wx.getSystemInfo( {
  17. success: ( res ) => {
  18. this.setData( {
  19. windowHeight: res.windowHeight
  20. })
  21. }
  22. })
  23. },
  24. // 上拉加载更多
  25. lower: function( e ) {
  26. var page = this.data.page+1;
  27. var nomore = this.data.nomore;
  28. if(page > this.data.totalPage){
  29. page = this.data.totalPage;
  30. nomore =true;
  31. }
  32. this.setData( {
  33. page: page,
  34. nomore:nomore
  35. })
  36. this.getDataFromServer( page );
  37. console.log( "上拉加载更多...." + page);
  38. },
  39. // 下拉返回
  40. upper: function( e ) {
  41. var page = this.data.page-1;
  42. if(page < 1){
  43. page = 1;
  44. }
  45. this.setData( {
  46. page: page
  47. })
  48. this.getDataFromServer( page );
  49. console.log( "下拉返回上页...." + page)
  50. },
  51. //获取网络数据的方法
  52. getDataFromServer: function (page) {
  53. console.log(page,this.data.totalPage);
  54. if(this.data.totalPage &&page > this.data.totalPage){
  55. page = this.data.totalPage;
  56. }
  57. var that = this;
  58. that.setData({
  59. loading: false,
  60. hasMore: true
  61. }),
  62. wx.request({
  63. url: 'url?p/'+page,
  64. data: {
  65. size: 10,
  66. parentsid: wx.getStorageSync('parentsid'),
  67. nurseryid: wx.getStorageSync('nurseryid'),
  68. classid: wx.getStorageSync('classid'),
  69. childid: wx.getStorageSync('childid')
  70. },
  71. header: {
  72. 'Content-Type': 'application/json'
  73. },
  74. success:function(res) {
  75. if(res.statusCode = 200){
  76. var items = res.data.dynamiclist;
  77. that.setData({
  78. items: items,
  79. totalPage: res.data.totalPage,
  80. loading: true,
  81. hasMore: false
  82. });
  83. }else{
  84. console.log("服务器异常");
  85. }
  86. }
  87. })
  88. }
  89. })

wxss:

  1. /*提示*/
  2. .tips {
  3. font-size: 28rpx;
  4. text-align: center;
  5. padding: 50rpx;
  6. color: #ccc;
  7. }
  8. .tips image {
  9. width: 40rpx;
  10. height: 40rpx;
  11. margin-right: 20rpx;
  12. }
  13. .tips image,
  14. .tips text {
  15. vertical-align: middle;
  16. }

三:全局变量

微信小程序里面有个app.js,我们可以在这个里面设置全局变量,像酱

  1. App({
  2. data:{
  3. servsers:""
  4. }
  5. })

在外面就这样引用就可以了,这个真的是简单

  1. getApp().data.servsers

四:更改navbar上面的文字

  1. wx.setNavigationBarTitle({
  2. title: '我是通过API设置的NavigationBarTitle'
  3. })

就酱便可以改变标题栏的文字了

最新评论

浮云而已 发表于 2022-5-25 20:06
vbnet源码下载

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表