VUE创建播发器组件并调用
欢迎来到我的友链小屋
首先用vue-cli创建前端项目
参考:https://www.cnblogs.com/ouyangkai/p/11549290.html
新建play.vue文件

编写play组件
<template>
<div>
<el-row>
<el-col :span="">
<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="" 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=""
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="../mp4/pkn0m-iuv0i.mp3" type="audio/mpeg" />
</audio>
</div>
</template> <script>
export default {
data () {
return {
music: {
isPlay: false,
currentTime: ,
maxTime: ,
volume:
}
}
},
mounted () {
this.$nextTick(() => {
setInterval(this.listenMusic, )
})
},
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 > ) {
this.music.volume =
}
if (this.music.volume < ) {
this.music.volume =
}
this.$refs.music.volume = this.music.volume /
},
formatTime (time) {
let it = parseInt(time)
let m = parseInt(it / )
let s = parseInt(it % )
return (m < ? '' : '') + parseInt(it / ) + ':' + (s < ? '' : '') + parseInt(it % )
}
}
}
</script>
以上代码直接复制保存即可
引用组件,在app.vue 中的 script 导入组件,并且在components中声明
<script>
import play from '../src/components/play'
export default { name: 'App',
components: {
play
} }
</script>
在app.vue template 里面的div 里面添加自定义play组件
<play />
运行项目:npm run dev

成功引用!
VUE创建播发器组件并调用的更多相关文章
- vue中的父子组件相互调用
vue中的父子组件相互调用: 1.vue子组件调用父组件方法:子组件:this.$emit('xx'); 父组件:定义yy方法,并在引用子组件时传参,如@xx="yy" 2.vue ...
- vue 创建单文件组件 注册组件 以及组件的使用
<template> <div id="app"> <v-home></v-home> <hr > <br> ...
- vue第六单元(vue的实例和组件-vue实例的相关属性和方法-解释vue的原理-创建vue的组件)
第六单元(vue的实例和组件-vue实例的相关属性和方法-解释vue的原理-创建vue的组件) #课程目标 掌握vue实例的相关属性和方法的含义和使用 了解vue的数据响应原理 熟悉创建组件,了解全局 ...
- 【vue】父组件主动调用子组件 /// 非父子组件传值
一 父组件主动调用子组件: 注意:在父组件使用子组件的标签上注入ref属性,例如: <div id="home"> <v-header ref="he ...
- Vue 创建组件的两种方法
地址:https://blog.csdn.net/cofecode/article/details/74634301 创建组件的两种方法 1.全局注册 2.局部注册 var child=Vue.ext ...
- Vue+elementUI 创建“回到顶部”组件
1.创建"回到顶部"组件 1 <template> 2 <transition name="el-fade-in"> 3 <div ...
- 关于vue.js 组件的调用
包子初学vue.js,有很多不明白的地方还请大家多多指教,在组件的调用的时候,包子有点懵,因为感觉调用组件的方式非常的麻烦,每一个都要实例化,不过,通过不断询问大牛们,我找到了,动态加载组件的方法~~ ...
- Vue 创建组件的方式
Vue 创建组件的方式 2018年08月07日 11:10:56 虔诚带着决然 阅读数:1015 版权声明:本文为博主原创文章,未经博主允许不得用做其他商业活动. https://blog.csd ...
- vue创建组件
vue创建组件是很容易的: js: Vue.component("component-item",{ //component-item就是我们在HTML页面上引用的组件,它会在 ...
随机推荐
- 【PHP】关于系统性能追踪工具molten
一.简介 关于molten的介绍网上有很多,是一个全链路追踪的工具,Molten可以看做是phptrace的的升级版(流行的php问题定位工具譬如phptrace,xhprof,这些工具可以自行Goo ...
- Linux计划任务,定时清空日志
以Ubuntu为例,利用系统自带计划任务,即cron ,计划任务,是任务在约定的时间执行已经计划好的工作,这是表面的意思.在Linux中,我们经常用到 cron 服务器来完成这项工作.cron服务器可 ...
- JMETER 使用随机变量
使用场景 在发起流程时,我们需要模拟实际情况,不同的用户可以产生不一样数量的流程实例,因此我们可以使用随机变量还进行模拟. 随机变量实例 1.添加一个循环计数器 2.添加一个循环 循环次数是根据随机变 ...
- 2017 ICPC网络赛(西安)--- Xor
题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai≤1,000 ...
- Comet 67E: ffort
题目传送门:Comet 67E. 用了个傻逼做法 A 了这题,欢迎观赏睿智做法! 题意简述: 题目说得很清楚了(这次是我不想写了). 题解: 为了方便,令 \(m\) 为敌人数,\(n\) 为己方士兵 ...
- webpy安装
C:\Users\ceshi>python -m pip install web.pyCollecting web.py Downloading web.py-0.38.tar.gz (91kB ...
- 前端小练习-Michael的博客界面(粗糙版)
michael-blog.html <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- 循环控制语句if 、for、case、while
if 循环控制(单分支与多分支) (1)单个判断(单分支循环): if [ 条件判断 ]; then 执行动作 fi if [ 条件判断 ]; then 执行动作 else 执行动作 fi 写入tes ...
- python利用beautifulsoup多页面爬虫
利用了beautifulsoup进行爬虫,解析网址分页面爬虫并存入文本文档: 结果: 源码: from bs4 import BeautifulSoup from urllib.request imp ...
- Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with na
问题: Springboot 启动时出错,报没法创建bean的错误,看到nested最后是关于mongoTemplate的错误. 过程: 看网上大多说的是修改mongoTemplate的配置,但是sp ...