DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Documenttitle>
<link
rel="stylesheet"
href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"
/>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.13/vue.js">script>
<script src="https://cdn.jsdelivr.net/npm/@unocss/runtime">script>
<script src="https://unpkg.com/element-ui/lib/index.js">script>
head>
<body>
<div id="app" class="h-90vh grid place-items-center">
<div>
<div v-for="(item,i) in list" class="mt-20px flex items-center">
<el-button type="primary">{{item.name}}el-button>
<div v-for="(sel,v) in item.tags" class="flex items-center">
<div
class="w-180px flex items-center border-1px border-solid ml-20px rounded-5px border-#6f6f6f"
>
<el-select
v-model="sel.value"
placeholder="请选择"
class="w-110px"
>
<el-option
v-for="item in getOption(item.tags)"
:key="item.value"
:label="item.label"
:value="item.value"
:disabled="item.disabled"
>
el-option>
el-select>
<el-input
class="!flex-1"
v-model="sel.num"
placeholder="请输入内容"
>el-input>
div>
<div
v-if="v == item.tags.length - 1 "
class="ml-10px text-26px"
@click="changeList('add',i)"
>
+
div>
<div
v-else
class="ml-10px text-26px"
@click="changeList('del',i,v)"
>
-
div>
div>
<div
v-if="item.tags == 0"
class="ml-10px text-26px"
@click="changeList('add',i)"
>
+
div>
div>
div>
div>
<script>
new Vue({
el: '#app',
data() {
return {
list: [
{
name: '选择一',
tags: [
{
value: '1',
num: 1,
},
],
},
{
name: '选择二',
tags: [],
},
],
options: [
{
value: '1',
label: '黄金糕',
},
{
value: '2',
label: '双皮奶',
},
{
value: '3',
label: '蚵仔煎',
},
{
value: '4',
label: '龙须面',
},
{
value: '5',
label: '北京烤鸭',
},
],
};
},
computed: {
getOption() {
return (data) => {
if (data == 0) {
return this.options;
} else {
let newData = this.options.map((v) => {
return {
...v,
disabled: data.map((e) => e.value).includes(v.value),
};
});
console.log(newData);
return newData;
}
};
},
},
methods: {
changeList(val, i, v) {
const change = {
add: () => {
if (this.list[i].tags.length == this.options.length) return;
this.list[i].tags.push({
value: '',
num: '',
});
},
del: () => {
this.list[i].tags.splice(v, 1);
},
};
change[val] ? change[val]() : '';
},
},
});
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153