美文网首页
小程序手风琴

小程序手风琴

作者: 燕十六_09ab | 来源:发表于2019-07-23 15:52 被阅读0次

1.记得在js代码部分,修改完数据之后,需要在this.satdata({})方法里面同步更新数据才可以

wxml部分

<view>

<view bindtap="fn" data-index="0">one</view>

<view hidden="{{arr[0]}}">1</view>

</view>

<view>

<view bindtap="fn" data-index="1">twe</view>

<view hidden="{{arr[1]}}">2</view>

</view>

<view>

<view bindtap="fn" data-index="2">three{{index}}</view>

<view hidden="{{arr[2]}}">3</view>

</view>

js部分

data: {

    index:0,

    arr:[false,true,true]

  },

  fn:function(e){ 

    var index = e.currentTarget.dataset.index;

    if (this.data.arr[index]) {

      for(let i=0;i<3;i++){

        console.log(i)

        this.data.arr[i] = true;

      }

      this.data.arr[index] = false;

    } else {

      this.data.arr[index] = true;

    }

    this.setData({

      arr: this.data.arr 

    })

  },

相关文章

网友评论

      本文标题:小程序手风琴

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