点击加载更多

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <div v-for="(item, key) in items" v-show="key<num">
      {{item}}
    </div>
    <span @click="showMore">{{txt}}</span>
  </div>
  <script src="https://unpkg.com/vue"></script>
  <script>
    var app = new Vue({
      el: '#app',
      data(){
        return{
          items: [
            'a',
            'b',
            'c',
            'd',
            'e',
            'f'
          ],
          isShow: true,
          txt: '显示全部',
          num: 3
        }
      },
      methods: {
        showMore(){
          console.log('1', this.isShow);
          this.isShow = !this.isShow;
          console.log('2', this.isShow);
          this.num = this.isShow? 3: this.items.length;
          this.txt = this.isShow?  '显示全部':'收起'
        }
      }
    })
  </script>
</body>
</html>

http://me.52fhy.com/demo/loadmore//1click.html

猜你喜欢

转载自blog.csdn.net/czy279470138/article/details/88025789
今日推荐