<template>
<div id="warp">
你选择的是:
<mark v-for="(item,index) in arr">
<span>{{item.name}}</span><a style="color: red;" href="javascript:;" @click="remove(index,item.id)">X</a>
</mark>
<!-- <span v-for="(item,index) in arr">{{item.name}}</span> -->
<div>
<ul>
<li v-for="(item,index) in phoneData">
<span>{{item.title}}:</span>
<a href="javascript:;" v-for="option,i in item.list" v-bind:class="{active:item.index===i}" @click="listBundle(option,index,i)">{{option}}
</a>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
data() {
return {
phoneData: [{
title: '手机',
list: ['小米6', '一加5', '荣耀9', '红米Note', '4X', '华为-mate 9', '红米4X', '美图M8', '锤子-坚果', 'PRO']
},
{
title: '平板',
list: ['小米6', '一加5', '荣耀9', '红米Note', '4X', '华为-mate 9', '红米4X', '美图M8', '锤子-坚果', 'PRO']
},
{
title: '电脑',
list: ['小米6', '一加5', '荣耀9', '红米Note', '4X', '华为-mate 9', '红米4X', '美图M8', '锤子-坚果', 'PRO']
},
{
title: '数码',
list: ['小米6', '一加5', '荣耀9', '红米Note', '4X', '华为-mate 9', '红米4X', '美图M8', '锤子-坚果', 'PRO']
}
],
arr: []
}
},
methods: {
listBundle(option, index, i) {
this.phoneData[index].index = i;
let param = {
id: index,
name: option
}
this.arr.push(param)
for (let i = 0; i < this.arr.length; i++) {
for (let j = i + 1; j < this.arr.length; j++) {
if (this.arr[i]['id'] == this.arr[j]['id']) {
this.arr[i]["name"] = this.arr[j]['name']
this.arr.splice(j, 1)
}
}
}
},
remove(index, id) {
this.$delete(this.arr, index, 1);
this.phoneData[id].index = -1;
}
}
}
</script>
<style scoped="scoped">
#warp {
width: 800px;
height: 260px;
margin: 0 auto;
border: 1px solid #ccc;
background-color: pink;
}
mark {
width: 100%;
height: 30px;
border: 1px solid pink;
}
li {
list-style: none;
float: left;
margin: 10px 20px 0 0;
width: 100%;
height: 70;
border-bottom: 1px dashed #ccc;
}
#warp div {
width: 100%;
height: 100%;
}
a {
display: inline-block;
margin: 10px 20px 0 0;
text-decoration: none;
}
.active {
background-color: red;
}
</style>
效果图