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 154 155 156 157 158 159 160 161 162 163 164 165 166
| <!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.0">
<title>Document</title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="../css/brandlist.css">
</head>
<body>
<div id="app">
<div class="card">
<div class="card-header">添加品牌</div>
<div class="card-body">
<form @submit.prevent="add">
<div class="form-row align-items-center">
<div class="col-auto">
<div class="input-group mb-2">
<div class="input-group-text">品牌名称</div>
<input type="text" class="form-control" placeholder="请输入品牌名称" v-model.trim="brand">
<button type="submit" class="btn btn-primary mb-2">添加</button>
</div>
</div>
</div>
</form>
</div>
</div>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>品牌名称</th>
<th>状态</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="item in list" :key="item.id">
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>
<div class="custom-control custom-switch">
<input class="custom-control-input" type="checkbox" :id="'cb' + item.id" v-model="item.status">
<label class="custom-control-label" :for="'cb' + item.id"> {{ item.status ? '已启用' : '已禁用' }}</label>
</div>
</td>
<td>{{ item.date }}</td>
<td><a href="#" @click.prevent="remove(item.id)">删除</a></td>
</tr>
</tbody>
</table>
</div>
</body>
<script src="./vue.js"></script>
<script>
new Vue({
el: "#app",
data: {
brand: "",
nextId: 4,
list: [
{ id: 1, name: "宝马", status: true, date: new Date() },
{ id: 2, name: "奥迪", status: false, date: new Date() },
{ id: 3, name: "奔驰", status: false, date: new Date() }
]
},
methods: {
remove(id) {
if (!confirm("确定要删除?")) return;
this.list = this.list.filter(item => item.id != id);
},
add() {
if (this.brand == "") return alert("没有填入内容");
this.list.push({id: this.nextId ++, name: this.brand, status: false, date: new Date()});
}
}
});
</script>
</html>
|