设为首页 加入收藏

TOP

Vue 常用指令(四)
2019-09-17 15:21:16 】 浏览:72
Tags:Vue 常用 指令
l: function () { this.interval = setInterval(() => { this.currentIndex = this.currentIndex + 1; if (this.currentIndex === this.imageArray.length) { this.currentIndex = 0; } }, 3000) }, changePic: function (index) { this.currentIndex = index; } }, created(){ this.setInterVal(); } }) </script> </body> </html>


四、案例:音乐播放器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>使用Vue实现音乐播放器</title>
  <script src="../statics/vue.min.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .active {
      background-color: red;
    }
  </style>
</head>
<body>

  <div id="app">
    <audio :src="songs[currentIndex].songSrc" controls="controls" loop="loop" autoplay="autoplay"></audio>
    <ul>
      <li v-for="song in songs" :key="song.id" @click="playSong(song.id)" :class="{ active: song.id===currentIndex+1 }">
        <h2>歌手:{{ song.artist }}</h2>
        <p>歌名:{{ song.name }}</p>
      </li>
    </ul>
  </div>

  <script>
    new Vue({
      el: "#app",
      data: {
        songs: [
          { id: 1, songSrc: '../medias/不再让你孤单.mp3', artist: "李必胜", name: '不再让你孤单' },
          { id: 2, songSrc: '../medias/漂洋过海来看你.mp3', artist: "Pizza Li", name: '漂洋过海来看你' },
          { id: 3, songSrc: '../medias/成都.mp3', artist: '必胜', name: '成都' },
          { id: 4, songSrc: '../medias/晚风.mp3', artist: 'Pizza', name: '晚风' },
        ],
        currentIndex: 0
      },
      methods: {
        playSong(index) {
          this.currentIndex = index - 1;
        }
      }
    })
  </script>

</body>
</html>

好了,以上就是vue常用指令介绍。




首页 上一页 1 2 3 4 5 6 7 下一页 尾页 4/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇小tips:JS/CSS实现字符串单词首.. 下一篇JS核心之DOM操作 下

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目