Vue一个简单dome
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>信息统计</title>
    <link rel="stylesheet" href="bootstrap.min.css"/>
    <script src="jquery-1.7.2.js"></script>
    <script src="bootstrap.js"></script>
    <script src="vue2018.js"></script>

    <script>
        window.onload = function () {
            new Vue({
                el: '#box',
                data: {
                    myData: [],
                    username: '',
                    age: '',
                    nowIndex:-100
                },
                methods: {
                    add: function () {
                        this.myData.push({
                            name: this.username,
                            age: this.age
                        });

                        this.username='';
                        this.age='';
                    },
                    deleteMag:function(n){
                        if(n==-2){
                            this.myData=[];
                        }else{
                            this.myData.splice(n,1);
                        }
                    }
                }
            });
        };
    </script>
</head>
<body>
<div class="container" id="box">
    <form role="form">
        <div class="form-group">
            <label for="username">用户名:</label>
            <input type="text" id="username" class="form-control" placeholder="输入用户名" v-model="username">
        </div>
        <div class="form-group">
            <label for="age">年 龄:</label>
            <input type="text" id="age" class="form-control" placeholder="输入年龄" v-model="age">
        </div>
        <div class="form-group">
            <input type="button" value="添加" class="btn btn-primary " @click="add()">
            <input type="reset" value="重置" class="btn btn-danger">
        </div>
    </form>
    <hr>
    <table class="table table-bordered table-hover">
        <caption class="h3 text-info">用户信息表</caption>
        <tr class="text-danger">
            <th class="text-center">序号</th>
            <th class="text-center">名字</th>
            <th class="text-center">年龄</th>
            <th class="text-center">操作</th>
        </tr>
        <tr class="text-center" v-for="(item,index) in myData">
            <td>{{index+1}}</td>
            <td>{{item.name}}</td>
            <td>{{item.age}}</td>
            <td>
                <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#layer" @click="nowIndex=index">删除</button>
            </td>
        </tr>
        <tr v-show="myData.length!=0">
            <td colspan="4" class="text-right">
                <button class="btn btn-danger btn-sm" @click="nowIndex=-2" data-toggle="modal" data-target="#layer">删除全部</button>
            </td>
        </tr>
        <tr v-show="myData.length==0">
            <td colspan="4" class="text-center text-muted">
                <p>暂无数据...</p>
            </td>
        </tr>
    </table>

    <!--模态框 动态弹出框-->
    <div role="dialog" class="modal fade bs-example-modal-sm" id="layer" >
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal">
                        <span>×</span>
                    </button>
                    <h4 class="modal-title">确认删除吗?</h4>
                </div>
                <div class="modal-body text-right">
                    <button class="btn btn-primary btn-sm" data-dismiss="modal">取消</button>
                    <button class="btn btn-danger btn-sm" data-dismiss="modal" @click="deleteMag(nowIndex)">确认</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Vue一个简单dome

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭