H5、微信小程序 push、unshift 使用报错

H5、微信小程序 push、unshift 使用报错

js
var once_time = null
var fast_index = 0
Page({
  data: {
    history:"",
    history_array:[],
    keywords: ['AAAAAA', 'BBBBBB', 'CCCCCC', 'DDDDDD', 'EEEEEE', 'FFFFFF', 'GGGGGG',],
    currentIndex:0,
  },
  // 清除历史
  clearHisFn(e){
    console.log('clear history')
    let that = this;
    that.setData({
      history_array :[],
      history:''
    })
  },
  // 暴力点击下一曲
  fastClickFn(){
    let that = this
    let currentIndex = that.data.currentIndex
    fast_index = currentIndex
    fast_index++
    console.log(fast_index)
    that.setData({
      currentIndex: fast_index
    })
  },
  // 防止暴力点击 操作
  timeOnceFn(){
    let that = this    
    fast_index++
    fast_index = (fast_index < 10) ? fast_index:0 
    console.log(fast_index)
    clearTimeout(once_time)
    once_time = setTimeout(function(res){
      that.setData({
        currentIndex: fast_index
      })
    },1000)
  },  
  // 添加历史记录
  addKeyWordsFn(e){
    let kw = e.currentTarget.dataset.key;
    let that = this
    let history = that.data.history
    history = kw + ',' + history
    let a = history.split(',')

    for(var i=1;i<a.length;i++){ // 从第二个开始判断 是否有存在重复
      if(a[0]==a[i]){        
        a.splice(i,1)
      }else if(a[i]==''){
        a.splice(i, 1)
      }
    }
    history = a.join(',')
    console.log(history)
    that.setData({
      history: history,
      history_array:a
    })
  },
  onLoad: function(res) {
    
  },
  onShow(){
    let that = this
    let currentIndex = that.data.currentIndex
    fast_index = currentIndex
  }
})
HTML
<view>测试字符串拼接生成</view>



<!-- 关键词 -->
<view class="title">关键词</view>
<view wx:for="{{keywords}}" wx:for-item="keys" wx:key="index" wx:for-index="index" class="keywords" bindtap="addKeyWordsFn" data-key="{{keys}}">
  {{keys}}
</view>

<!-- 历史记录 -->
<view class="title">历史记录
  <view catchtap="clearHisFn">清除记录</view>
</view>
<view wx:for="{{history_array}}" wx:for-item="key" wx:key="index" wx:for-index="index" class="keywords">
  {{key}}
</view>

<!-- 下一曲 暴力点击测试 -->
<view catchtap="fastClickFn">暴力点击下一曲</view>
<view catchtap="timeOnceFn">增加防暴力点击锁 点击下一曲</view>
css
.keywords {
  background: #ff6767;
  color: #fff;
  font-size: 28rpx;
  border-radius: 10rpx;
  width: auto;
  display: inline-block;
  padding:10rpx 25rpx;
  margin: 10rpx;
}
.title {
  width: 100%;
  background: #f5f5f5;
  font-size: 32rpx;
  font-weight: 700;
  padding: 10rpx ;
  margin: 20rpx  0;
}
.title>view{
  width: 30vw;
  text-align: center;
  background: #cccccc;
  color: #ffffff;
  padding: 10rpx 20rpx;
  border-radius: 10rpx;
  margin: 20rpx 0 0 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值