vue-one_demo_music
简单的音乐盒子
利用计算属性(监听数据),解决上一首,下一首,点击切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
<style>
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
} /* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
} body {
line-height: 1;
} ol, ul {
list-style: none;
} blockquote, q {
quotes: none;
} blockquote:before, blockquote:after,
/* 清除浮动*/
q:before, q:after {
content: '';
content: none;
} table {
border-collapse: collapse;
border-spacing: 0;
}
li{
border: 2px solid deepskyblue;
padding: 5px;
}
</style>
</head>
<body>
<!-- autoplay 自动播放 调整音量 自动循环 @ended 自动下一首 -->
<div id="music">
<!-- :scr 要链接下面的数据 要通过指令系统-->
<audio :src="currentSong" autoplay controls autoloop @ended = 'nextSong()'></audio>
<ul>
<!-- 点击换歌 -->
<li v-for = '(item, i) in songs' @click = "currentHandler(i)">
<h3>作者:{{item.author}}</h3>
<p>{{item.name}}</p>
</li>
</ul>
<button @click = 'upSong'>上一首</button> <!-- 方法名,不加参数可以不写() -->
<button @click = 'nextSong'>下一首</button>
<button @click = 'addSong'>添加</button>
<!-- @click 方法-->
</div> <!--MVVM Model==》数组 数据库 View == document 标签 上面的div VM--> <script type="text/javascript" src="vue.js"></script>
<script type="text/javascript">
// 数据的双向绑定 m<=>v
var songs = [
{id:1,src:'./audios/audios/1.mp3',name:"水瓶座",author:'陈晓东'},
{id:2,src:'./audios/audios/2.mp3',name:"倾城",author:'陈奕迅'},
{id:3,src:'./audios/audios/3.mp3',name:"海阔天空",author:'Beyond'},
{id:4,src:'./audios/audios/4.mp3',name:"我很快乐",author:'刘惜君'} ];
var music = new Vue({
el:'#music',
data:{
// 数据属性Model
songs : songs,
// currentSong : "./audios/audios/1.mp3",
index:0
},
methods:{
// 事件名方法要在这里声明
currentHandler(i){ // 点击歌名换歌
this.index = i; // 这里绑定了数据属性,一改就调动下面的计算属性
// this.currentSong = this.songs[i].src;
},
nextSong(){
this.index++;
// this.currentSong = this.songs[this.index].src;
},
upSong(){
this.index = this.index-1;
// this.currentSong = this.songs[this.index].src;
},
addSong(){
this.songs.push( {id:5,src:'./audios/audios/4.mp3',name:"我很快乐",author:'刘惜君'})
}
},
computed:{ // 计算属性,实行监听
currentSong(){
return this.songs[this.index].src
}
}
})
</script>
</body>
</html>
vue-one_demo_music的更多相关文章
- Vue.js 和 MVVM 小细节
MVVM 是Model-View-ViewModel 的缩写,它是一种基于前端开发的架构模式,其核心是提供对View 和 ViewModel 的双向数据绑定,这使得ViewModel 的状态改变可以自 ...
- wepack+sass+vue 入门教程(三)
十一.安装sass文件转换为css需要的相关依赖包 npm install --save-dev sass-loader style-loader css-loader loader的作用是辅助web ...
- wepack+sass+vue 入门教程(二)
六.新建webpack配置文件 webpack.config.js 文件整体框架内容如下,后续会详细说明每个配置项的配置 webpack.config.js直接放在项目demo目录下 module.e ...
- wepack+sass+vue 入门教程(一)
一.安装node.js node.js是基础,必须先安装.而且最新版的node.js,已经集成了npm. 下载地址 node安装,一路按默认即可. 二.全局安装webpack npm install ...
- Vue + Webpack + Vue-loader 系列教程(2)相关配置篇
原文地址:https://lvyongbo.gitbooks.io/vue-loader/content/ 使用预处理器 在 Webpack 中,所有的预处理器需要和一个相应的加载器一同使用.vue- ...
- Vue + Webpack + Vue-loader 系列教程(1)功能介绍篇
原文地址:https://lvyongbo.gitbooks.io/vue-loader/content/ Vue-loader 是什么? vue-loader 是一个加载器,能把如下格式的 Vue ...
- 关于Vue.js 2.0 的 Vuex 2.0,你需要更新的知识库
应用结构 实际上,Vuex 在怎么组织你的代码结构上面没有任何限制,相反,它强制规定了一系列高级的原则: 应用级的状态集中放在 store 中. 改变状态的唯一方式是提交mutations,这是个同步 ...
- Vue.js 2.0 和 React、Augular等其他框架的全方位对比
引言 这个页面无疑是最难编写的,但也是非常重要的.或许你遇到了一些问题并且先前用其他的框架解决了.来这里的目的是看看Vue是否有更好的解决方案.那么你就来对了. 客观来说,作为核心团队成员,显然我们会 ...
- 窥探Vue.js 2.0 - Virtual DOM到底是个什么鬼?
引言 你可能听说在Vue.js 2.0已经发布,并且在其中新添加如了一些新功能.其中一个功能就是"Virtual DOM". Virtual DOM是什么 在之前,React和Em ...
- 初探Vue
Vue.js(读音/vju:/,类似于view),是近来比较火的前端框架,但一直没有怎么具体了解.实现过,就知道个啥的MVVM啦,数据驱动啦,等这些关于Vue的虚概念. 由于最近,小生在公司中,负责开 ...
随机推荐
- js 代码执行时间
<html> <head> </script> <script> var sTime=new Date().getTime(); alert(&qu ...
- Docker 坑点记录
1 关于 Docker Windows 文件夹问题 C:\Users Docker Machine tries to auto-share your /Users (OS X) or C:\Users ...
- JSch 实现 SSH 端口转发
package com.yinger.webservice.test; import java.sql.Connection; import java.sql.DriverManager; impor ...
- 从SynchronizedCollection说起
SynchronizedCollection简介 SynchronizedCollection是Collections下所有现场安全集合的父类,并发安全集合可以分为三类,一种是比较老的实现,例如vec ...
- Angular Material 教程之布局篇
Angular Material 教程之布局篇 (一) : 布局简介https://segmentfault.com/a/1190000007215707 Angular Material 教程之布局 ...
- Python实现H5页面
from selenium import webdriver mobile_emulation = {'deviceName':'iPhone X'} options = webdriver.Chro ...
- iometer测试磁盘IO性能
of Outstanding I/Os per target – 被选中worker的每个磁盘一次所允许的未处理的异步I/O的数量.模拟测试多个应用向 IO 请求读写,默认是 1.通常不用这个参数,除 ...
- CentOS 7.2下编译安装PHP7.0.10+MySQL5.7.14+Nginx1.10.1
一.安装前的准备工作 1.yum update #更新系统 2.yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2 ...
- 在接口请求时报错Unrecognized field "zZF1"
这个问题是json序列化问题,当参数中出现大写字母组成的字段时(例如:ZZF1),此时需在字段上加入注解:@JsonProperty(value = "ZZF1")
- yii2手动添加插件PHPExcel
1.下载地址:https://github.com/PHPOffice/PHPExcel 2.解压并修改文件名为phpexcel 之后在yii项目的vendor目录下创建一个文件夹命名为phpoffi ...