品牌案例--增,删,查

        <div class="panel panel-info">
            <div class="panel-heading">
                <h3 class="panel-title">Panel title</h3>
            </div>
            <div class="panel-body">
                Panel content

                <form action="" method="POST" class="form-inline" role="form">

                    <div class="form-group">
                        <label class="" for="">ID</label>
                        <input v-model:value="carId" type="text" class="form-control" id=""
                            placeholder="Input field">
                    </div>
                    <div class="form-group">
                        <label class="" for="">NAME</label>
                        <input v-model:value="carName" type="text" class="form-control" id=""
                            placeholder="Input field">
                    </div>



                    <button type="submit" @click.prevent="add" class="btn btn-primary">添加</button>

                    <div class="form-group">
                        <label class="" for="">搜索</label>
                        <input v-model:value="keyword" type="text" class="form-control" id=""
                            placeholder="Input field">
                    </div>
                </form>

            </div>

            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>id</th>
                        <th>name</th>
                        <th>time</th>
                        <th>operation</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item, index) in search()" :key=index>
                        <td>{{item.id}}</td>
                        <td>{{item.name}}</td>
                        <td>{{item.time}}</td>
                        <td>

                            <button @click="deleteCar(item.id)" type="button" class="btn btn-info">删除</button>

                        </td>
                    </tr>
                </tbody>
            </table>

        </div>

    </div>
</div>
<script>
    let vm = new Vue({
        el: "#app",
        data: {
            carList: [
                {
                    id: 1,
                    name: "宝马",
                    time: new Date()
                },
                {
                    id: 2,
                    name: "本吹",
                    time: new Date()
                },
                {
                    id: 3,
                    name: "五零",
                    time: new Date()
                },
            ],
            carId: "",
            carName: "",
            keyword: ""
        },
        methods: {
            add: function () {
                添加元素,先整理对象,push
                if (this.carId  && this.carName ) {
                    let obj = {
                        id: this.carId,
                        name: this.carName,
                        time: new Date
                    }
                    this.carList.push(obj),
                        this.carName = "",
                        this.carId = ""

                } else {
                    alert("不能为空")
                }
            },
            deleteCar: function (carId) {
                this.carList.splice(this.carList.findIndex(item => item.id == carId), 1)
            },
            search() {
                filter返回符合条件的数组
                includes方法判断一个数组是否包含指定值
                return this.carList.filter(item => item.name.includes(this.keyword))
            }
        },
    })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值