vueJS 012 crd 简易

<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/normalize.css">
    <link rel="stylesheet" href="../css/bootstrap.css">
    <script src="../js/vue2.6.11.js"></script>
    <style type="text/css">

    </style>
</head>
<body>
<div id="app">
    <div class="form-row form-check-inline">
        <div class="col">
            <input type="text" class="form-control" placeholder="学名" v-model="name">
        </div>
        <div class="col">
            <input type="text" class="form-control" placeholder="生存状态" v-model="survive">
        </div>
        <div class="btn-group" role="group">
            <button class="btn-primary btn" @click="add">添加</button>
        </div>
        <div class="col">
            <input type="text" class="form-control" placeholder="请输入查询内容" v-model="keywords">
        </div>
    </div>
    <table class="table table-striped">
        <thead>
        <tr>
            <th scope="col">序号</th>
            <th scope="col">学名</th>
            <th scope="col">生存状态</th>
            <th scope="col">记录时间</th>
            <th scope="col">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="plant in search3()" :key="plant.id">
            <td v-cloak>{{plant.id}}</td>
            <td v-cloak>{{plant.name}}</td>
            <td v-cloak>{{plant.survive}}</td>
            <td v-cloak>{{plant.ctime}}</td>
            <td>
                <button type="button" class="btn btn-outline-danger" @click="del2(plant.id)">删除</button>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<script>
    let vm = new Vue({
        el: '#app',
        data: {
            id: 3,
            name: "",
            survive: "",
            ctime: "",
            keywords:"",
            plants: [
                {id: 1, name: "百山祖冷杉", survive: "已灭绝", ctime: new Date()}
                , {id: 2, name: "普陀鹅耳枥", survive: "已灭绝", ctime: new Date()}
                , {id: 3, name: "松树", survive: "存在", ctime: new Date()}
            ]
        },
        methods: {
            add() {
                this.plants.push({id: ++this.id, name: this.name, survive: this.survive, ctime: new Date()});
            }
            , del2(id) {
                let index = this.plants.findIndex(item => {
                    if (item.id === id) {
                        return true;
                    }
                });
                this.plants.splice(index, 1);
            }
            , del3(id) {
                let index = this.plants.some((item, i) => {
                    if (item.id === id) {
                        this.plants.splice(id, 1);
                        return true;
                    }
                });
            }
            ,search2(){
                let rList=[];
                this.plants.forEach(item => {
                    if (item.name.indexOf(this.keywords)!=-1
                        || item.survive.indexOf(this.keywords)!=-1){
                        rList.push(item);
                    }
                });
                return rList;
            }
            ,search3(){
                return this.plants.filter(item => {
                    if (item.name.includes(this.keywords)
                        || item.survive.includes(this.keywords)){
                        return item;
                    }
                });
            }
        }
    });
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值