<template v-for="item in buttonList">
<el-tooltip class="item" effect="dark" :content="item.content" placement="top-start"
v-if="item.content == '上一首' || item.content == '开始' && !playState || item.content == '暂停' && playState || item.content == '下一首' || item.content == '循环播放' && playModule || item.content == '顺序播放' && !playModule">
<el-button type="text" :class="'el-icon-' + item.icon" v-on:click="btn(item.event)"></el-button>
</el-tooltip>
</template>
btn(event) {
this[event]()
},
// 上一首
beforeMusic() {
},
// 开始
beginMusic() {
this.playState = true
alert("正在播放")
},
// 暂停
stopMusic() {
this.playState = false
alert("暂停播放")
},
// 下一首
afterMusic() {
},
// 循环播放
music() {
this.playModule = false
alert("循环播放")
},
// 顺序播放
stepMusic() {
this.playModule = true
alert("顺序播放")
},
buttonList: [
{
icon: "caret-left",
content: "上一首",
event: "beforeMusic",
},
{
icon: "video-play",
content: "开始",
event: "beginMusic",
},
{
icon: "video-pause",
content: "暂停",
event: "stopMusic",
},
{
icon: "caret-right",
content: "下一首",
event: "afterMusic",
},
{
icon: "refresh",
content: "循环播放",
event: "music",
},
{
icon: "s-operation",
content: "顺序播放",
event: "stepMusic",
}
]
1.需要注意:绑定事件不能使用@只能使用v-on
2.通过一个中间方法进行调用,直接写v-on:click="item.event"无效