欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于vue-element組件實(shí)現(xiàn)音樂播放器功能

 更新時(shí)間:2018年05月06日 16:52:40   作者:簡(jiǎn)書辣子雞  
這篇文章主要介紹了基于vue-element組件實(shí)現(xiàn)音樂播放器功能,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

最近在寫一個(gè)基于 github-page 和 gist 的博客, 想加個(gè)音樂播放器, 做了一個(gè)早上, 發(fā)出來分享一下

演示地址 https://github-laziji.github.io

效果

使用到的組件

element組件

  • 布局 Layout
  • 按鈕 Button
  • 滑塊 Slider
  • 進(jìn)度條 Progress
  • 彈出框 Popover

html5組件

audio

實(shí)現(xiàn)代碼

更詳細(xì)的實(shí)現(xiàn)可以看 https://github.com/GitHub-Laziji/vblog

<template>
  <div>
  <el-row>
   <el-col :span="4">
    <el-popover
    placement="top-start"
    trigger="hover">
     <div style="text-align: center">
      <el-progress 
      color="#67C23A"
      type="circle" 
      :percentage="music.volume"></el-progress><br>
      <el-button 
      @click="changeVolume(-10)"
      icon="el-icon-minus" 
      circle></el-button>
      <el-button 
      @click="changeVolume(10)"
      icon="el-icon-plus" 
      circle></el-button>
     </div>
     <el-button 
     @click="play"
     id="play"
     slot="reference"
     :icon="music.isPlay?'el-icon-refresh':'el-icon-caret-right'" 
     circle></el-button>
    </el-popover>
   </el-col>
   <el-col :span="14" style="padding-left: 20px">
    <el-slider
    @change="changeTime"
    :format-tooltip="formatTime"
    :max="music.maxTime"
    v-model="music.currentTime" 
    style="width: 100%;"></el-slider>
   </el-col>
   <el-col :span="6" style="padding: 9px 0px 0px 10px;color:#909399;font-size: 13px">
    {{formatTime(music.currentTime)}}/{{formatTime(music.maxTime)}}
   </el-col>
  </el-row>
  <audio ref="music" loop autoplay> 
   <source src="http://sc1.111ttt.cn:8282/2018/1/03m/13/396131232171.m4a?tflag=1519095601&pin=6cd414115fdb9a950d827487b16b5f97#.mp3" type="audio/mpeg">
  </audio>
 </div>
</template>
<script>
 export default{
  data(){
   return {
    music:{
     isPlay:false,
     currentTime:0,
     maxTime:0,
     volume:100
    }
   }
  },
  mounted(){
   this.$nextTick(()=>{
    setInterval(this.listenMusic,1000)
   })
  },
  methods:{
   listenMusic(){
    if(!this.$refs.music){
     return
    }
    if(this.$refs.music.readyState){
     this.music.maxTime = this.$refs.music.duration
    }
    this.music.isPlay=!this.$refs.music.paused
    this.music.currentTime = this.$refs.music.currentTime
   },
   play(){
    if(this.$refs.music.paused){
     this.$refs.music.play()
    }else{
     this.$refs.music.pause()
    }
    this.music.isPlay=!this.$refs.music.paused
    this.$nextTick(()=>{
     document.getElementById('play').blur()
    })
   },
   changeTime(time){
    this.$refs.music.currentTime = time
   },
   changeVolume(v){
    this.music.volume += v 
    if(this.music.volume>100){
     this.music.volume = 100
    }
    if(this.music.volume<0){
     this.music.volume = 0
    }
    this.$refs.music.volume = this.music.volume/100
   },
   formatTime(time){
    let it = parseInt(time)
    let m = parseInt(it/60)
    let s = parseInt(it%60)
    return (m<10?"0":"")+parseInt(it/60)+":"+(s<10?"0":"")+parseInt(it%60)
   }
  } 
 }
</script>

總結(jié)

以上所述是小編給大家介紹的基于vue-element組件實(shí)現(xiàn)音樂播放器功能,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

  • electron踩坑之dialog中的callback解決

    electron踩坑之dialog中的callback解決

    這篇文章主要介紹了electron踩坑之dialog中的callback解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Vue3狀態(tài)管理之Pinia的入門使用教程

    Vue3狀態(tài)管理之Pinia的入門使用教程

    Pinia是Vue.js的輕量級(jí)狀態(tài)管理庫(kù),比起vue3中的Vuex狀態(tài)管理,pinia更輕量,更容易使用,下面這篇文章主要給大家介紹了關(guān)于Vue3狀態(tài)管理之Pinia的入門使用教程,需要的朋友可以參考下
    2022-04-04
  • 帶你一文了解Vue生命周期鉤子

    帶你一文了解Vue生命周期鉤子

    生命周期鉤子又被叫做生命周期時(shí)間,生命周期函數(shù),生命周期鉤子就是vue生命周期中出發(fā)的各類事件,這些事件被稱為生命周期鉤子,下面這篇文章主要給大家介紹了關(guān)于Vue生命周期鉤子的相關(guān)資料,需要的朋友可以參考下
    2022-06-06
  • vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能示例

    vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能示例

    這篇文章主要介紹了vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能,涉及基于vue的事件響應(yīng)、數(shù)據(jù)交互等相關(guān)操作技巧,需要的朋友可以參考下
    2019-05-05
  • vue項(xiàng)目實(shí)現(xiàn)m3u8流媒體播放詳細(xì)圖文教程

    vue項(xiàng)目實(shí)現(xiàn)m3u8流媒體播放詳細(xì)圖文教程

    m3u8是一種常用的視頻流媒體格式,通常用于在Web上播放視頻,這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目實(shí)現(xiàn)m3u8流媒體播放的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-09-09
  • VUE中v-on:click事件中獲取當(dāng)前dom元素的代碼

    VUE中v-on:click事件中獲取當(dāng)前dom元素的代碼

    這篇文章主要介紹了VUE中v-on:click事件中獲取當(dāng)前dom元素的代碼,文中同時(shí)給大家提到了v-on:click獲取當(dāng)前事件對(duì)象元素的方法,需要的朋友可以參考下
    2018-08-08
  • 解決element ui el-row el-col里面高度不一致問題

    解決element ui el-row el-col里面高度不一致問題

    這篇文章主要介紹了解決element ui el-row el-col里面高度不一致問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • 基于Vue實(shí)現(xiàn)HTML轉(zhuǎn)PDF并導(dǎo)出

    基于Vue實(shí)現(xiàn)HTML轉(zhuǎn)PDF并導(dǎo)出

    這篇文章主要為大家介紹了三種方法,可以實(shí)現(xiàn)將HTML頁(yè)面轉(zhuǎn)為PDF并實(shí)現(xiàn)下載。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以學(xué)習(xí)一下
    2022-04-04
  • element表單el-form的label自適應(yīng)寬度的實(shí)現(xiàn)

    element表單el-form的label自適應(yīng)寬度的實(shí)現(xiàn)

    本文主要介紹了element表單el-form的label自適應(yīng)寬度的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • vue3的watch用法以及和vue2中watch的區(qū)別

    vue3的watch用法以及和vue2中watch的區(qū)別

    這篇文章主要介紹了vue3的watch用法以及和vue2中watch的區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04

最新評(píng)論