当前位置:网站首页>品牌列表案例
品牌列表案例
2022-07-27 18:12:00 【宇智波-林中路】
增删查、过滤器
第1步:
npm init -y
生成 .json文件
第2步:
npm i bootstrap -S
生成2个文件
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap-grid.min.css"><!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>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
<link
rel="stylesheet"
href="./node_modules/bootstrap/dist/css/bootstrap.min.css"
/>
</head>
<body>
<div id="app">
<div>
<label>Id:</label>
<input type="text" v-model="id" />
<label>Name:</label>
<input type="text" v-model="name" />
<input
type="button"
value="添加"
class="btn btn-primary"
@click="add"
/>
<label>按照品牌名称取检索::</label>
<input type="text" v-model="keyWords" @change="searchByName" />
</div>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Ctime</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(item,index) in searchByName()" :key="item.id">
<td>{
{item.id}}</td>
<td>{
{item.name}}</td>
<td>{
{item.ctime}}</td>
<td>
<!-- 避免用一元操作符作为属性名delete -->
<!--传索引 -->
<a href="http://www.baidu.com" @click.prevent="del(index)"
>删除</a
>
<!-- 传id -->
<!-- <a href="http://www.baidu.com" @click.prevent="del(item.id)"
>删除</a
> -->
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<script>
const app = new Vue({
el: "#app",
data: {
id: "",
name: "",
keyWords: "",
list: [
{ id: 1, name: "奔驰", ctime: new Date() },
{ id: 2, name: "宝马", ctime: new Date() },
{ id: 3, name: "千里马", ctime: new Date() },
{ id: 4, name: "奔奔", ctime: new Date() },
],
},
methods: {
// 添加
add() {
this.list.push({ id: this.id, name: this.name, ctime: new Date() });
this.id = this.name = "";
},
// 删除(根据索引)
del(index) {
// console.log(index);
this.list.splice(index, 1);
},
// 删除(根据id)
// del(id) {
// const index = this.list.findIndex((item) => {
// return item.id == id;
// });
// this.list.splice(index, 1);
// // findIndex 如果为true 返回数组下标
// },
// 查找
// 第1种
searchByName() {
let result = [];
// 循环list中的每一项,拿到这一项之后,判断名称中是否包含:关键字,如果包含,则把这一项添加到result 中
for (let i = 0; i < this.list.length; i++) {
if (this.list[i].name.indexOf(this.keyWords) != -1) {
result.push(this.list[i]);
}
}
return result;
},
// searchByName() {
// let result = [];
// // 循环list中的每一项,拿到这一项之后,判断名称中是否包含:关键字,如果包含,则把这一项添加到result 中
// for (let i = 0; i < this.list.length; i++) {
// // includes 有为true
// if (this.list[i].name.includes(this.keyWords)) {
// result.push(this.list[i]);
// }
// }
// return result;
// },
// 第2种(高阶函数)
// searchByName() {
// const newArr = this.list.filter((item) => {
// // return item.name.indexOf(this.keyWords) != -1;
// return item.name.includes(this.keyWords);
// });
// return newArr;
// },
// searchByName() {
// return this.list.filter((item) => {
// // return item.name.indexOf(this.keyWords) != -1;
// return item.name.includes(this.keyWords);
// });
// },
},
});
</script>全局过滤器,处理时间
npm i moment -s边栏推荐
- 用户和权限创建普通用户
- Common methods of object learning [clone and equals]
- [efficiency] abandon notepad++, this open source substitute is more awesome!
- 金仓数据库 KingbaseES异构数据库移植指南 (3. KingbaseES移植能力支撑体系)
- [Alibaba security × ICDM 2022] 200000 bonus pool! The risk commodity inspection competition on the large-scale e-commerce map is in hot registration
- 【防抖与节流】
- MYSQL设计优化生成列
- How bad can a programmer be?
- Analysis on the optimization of login request in IM development of instant messaging mobile terminal
- 学术分享 | 清华大学 康重庆:电力系统碳计量技术与应用(Matlab代码实现)
猜你喜欢
![[efficiency] abandon notepad++, this open source substitute is more awesome!](/img/41/495bbe4d1e6d953ba5c4d8984f81e7.jpg)
[efficiency] abandon notepad++, this open source substitute is more awesome!

如何监控NVIDIA Jetson的的运行状态和使用情况

【深度学习】Pytorch Tensor 张量

Introduction to JVs Foundation

Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24
![[deep learning] video classification technology sorting](/img/bf/422d4ef342199966bbdaae06977699.png)
[deep learning] video classification technology sorting

从0开始写bootloader

A layered management method of application layer and hardware layer in embedded system

Preprocessing and macro definition

【阿里安全 × ICDM 2022】20万奖金池!大规模电商图上的风险商品检测赛火热报名中!...
随机推荐
SQL高级技巧CTE和递归查询
RK3399平台开发系列讲解(进程篇)15.36、理解进程和协程
推荐一款强大的搜索工具Listary
Software test interview question: count the number in a queue, how many positive numbers and how many negative numbers, such as [1, 3, 5, 7, 0, -1, -9, -4, -5, 8]
面了个腾讯拿38K跳槽出来的,见识到了真正的测试天花板
How bad can a programmer be?
[design tutorial] yolov7 target detection network interpretation
[rctf2015]easysql-1 | SQL injection
人家这才叫软件测试工程师,你那只是混口饭吃(附HR面试宝典)
【效率】弃用 Notepad++,这款开源替代品更牛逼!
用户和权限撤销用户权限
【深度学习】Pytorch Tensor 张量
Why are TS slice files generated when easycvr platform turns off video recording?
IM即时通讯开发如何提升移动网络下图片传输速度和成功率
用户和权限创建普通用户
Flask-MDict搭建在线Mdict词典服务
leetcode:1498. 满足条件的子序列数目【排序 + 二分 + 幂次哈希表】
vi工作模式(3种)以及模式切换(转换)
Summary of simple topics
IE11 下载doc pdf等文件的方法