• 微信小程序技巧记录


    1.直接在app.json中添加pages,会自动按照路径生成page目录文件;

    2.动态修改样式:

    /**
       * 页面的初始数据
       */
      data: {
        authorInfo: [],
        article: [],
        index: [],
        attentionBackgroundColor: 'white',
        attentionTextColor: 'black'
      },
    
    
attentionAction: function() {
        wx.showToast({
          title: '关注成功',
        });
        // 动态设置颜色和背景
        var that = this;
        var bgColor = this.data.attentionBackgroundColor == 'red' ? 'white' : 'red';
        var textColor = this.data.attentionTextColor == 'black' ? 'white' : 'black';
        // 设置背景颜色数据
        this.setData({
          attentionBackgroundColor: bgColor,
          attentionTextColor: textColor
        });
      },

    设置样式处:

     <view class='follow' bindtap='attentionAction' style='background-color:{{attentionBackgroundColor}};color: {{attentionTextColor}}'>
              关注
     </view>

    3.下拉刷新,上拉加载:

    app.json设置enablePullDownRefresh:

      "window": {
        "backgroundTextStyle": "light",
        "navigationBarBackgroundColor": "#fff",
        "navigationBarTitleText": "网易蜗牛读书",
        "navigationBarTextStyle": "black",
        "enablePullDownRefresh": true
      },

    当前页设置enablePullDownRefresh为true。

    js实现下拉刷新,上拉加载:

     /**
       * 页面相关事件处理函数--监听用户下拉动作
       */
      onPullDownRefresh: function () {
        wx.showNavigationBarLoading() //在标题栏中显示加载
    
        //模拟加载
        setTimeout(function () {
          // complete
          wx.hideNavigationBarLoading() //完成停止加载
          wx.stopPullDownRefresh() //停止下拉刷新
        }, 1500);
      },
    
      /**
       * 页面上拉触底事件的处理函数
       */
      onReachBottom: function () {
        console.log('加载更多');
        var that = this;
        setTimeout(() => {
          wx.request({
            url: 'https://www.easy-mock.com/mock/5a23a9a2ff38a436c591b6fa/getArticInfo',
            success: function (res) {
              console.log(res.data.data.index);
              console.log(res.data.data.articleInfo);
              that.setData({
                isHideLoadMore: true,
                authors: res.data.data.index,
                id: res.data.data.articleInfo
              })
              wx.hideLoading();
            }
          })
        }, 1000);
      },
  • 相关阅读:
    523. Continuous Subarray Sum
    517. Super Washing Machines
    516. Longest Palindromic Subsequence
    486. Predict the Winner
    467. Unique Substrings in Wraparound String
    474. Ones and Zeroes
    语法小结
    互评作业:使用数组
    466. Count The Repetitions
    1052 卖个萌 (20 分)
  • 原文地址:https://www.cnblogs.com/pengsi/p/8251976.html
Copyright © 2020-2023  润新知