vue.js筛选功能(基于1.0版本)

<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>Document</title>

        <style type="text/css">
            #tb {
                width: 800px;
                border-collapse: collapse;
                margin: 20px auto;
            }
            
            #tb th {
                background-color: #0094ff;
                color: white;
                font-size: 16px;
                padding: 5px;
                text-align: center;
                border: 1px solid black;
            }
            
            #tb tr td {
                padding: 5px;
                text-align: center;
                border: 1px solid black;
            }
        </style>
        <script src="js/vue1026.js"></script>
    </head>

    <body>
        <div id="app">
            <input type="text" v-model="id" />
            <input type="text" v-model="pname" />
            <!--//筛选输入框-->
            <input type="text" placeholder="请输入筛选内容" v-model="sname" />
            <button @click="addData">添加</button>

            <table id="tb">
                <tr>
                    <th>编号</th>
                    <th>品牌</th>
                    <th>时间</th>
                    <th>操作</th>
                </tr>
                <tr v-show="list.length == 0">
                    <td colspan="4">当前列表无数据</td>
                </tr>
                <!--筛选值绑定-->
                <tr v-for="item in list | filterBy sname in 'name'">
                    <td>{{item.id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.ctime}}</td>
                    <td>
                        <a href="javascript:void(0)" @click="delData(item.id)">删除</a>
                    </td>
                </tr>
            </table>
        </div>
    </body>

    <script>
        new Vue({
            el: '#app',
            data: {
                list: [{
                    id: 1,
                    name: '奔驰',
                    ctime: new Date
                }],
                id: 0,
                pname: '',
                sname: '' /*筛选值定义*/
            },
            methods: {
                addData: function() {
                    var p = {
                        id: this.id,
                        name: this.pname,
                        ctime: new Date()
                    };
                    this.list.push(p);
                    this.id = 0;
                    this.pname = '';
                },
                delData: function(id) {
                    if(!confirm('是否要删除数据')) {
                        return;
                    }
                    var index = this.list.findIndex(function(item) {
                        return item.id == id
                    })
                    this.list.splice(index, 1)
                }
            }

        });
    </script>

</html>

本文属于学习笔记

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值