zoukankan      html  css  js  c++  java
  • 练习vue(用户管理)1

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title>练习vue(用户管理)</title>
            <link rel="stylesheet" href="css/bootstrap.min.css" />
            <script src="js/vue.js"></script>
            <script src="js/jquery-3.2.1.min.js"></script>
            <script src="js/bootstrap.min.js"></script>
            <script type="text/javascript">
                window.onload = function() {
                    let vm = new Vue({
                        el: '.container',
                        data: {
                            users: [
                                { name: 'tom', age: 24, email: 'tom@itany.com' },
                                { name: 'jack1', age: 23, email: 'jack@1232.com' },
                                { name: 'jack222', age: 23, email: 'jack@1232.com' }
                            ],
                            user: {},
                            nowIndex: -1
                        },
                        methods: {
                            adduser() {
                                this.users.push(this.user);
                                this.user = {};
                            },
                            deluser() {
                                if(this.nowIndex === -1) {
                                    this.users = {}
                                } else {
                                    this.users.splice(this.nowIndex, 1);
                                }
    
                            },
                            print(e) {
                                console.log(e);
                            }
                        }
                    });
                }
            </script>
        </head>
    
        <body>
            <div class="container">
                <h3 class="text-center">添加用户</h3>
                <form class="form-horizontal">
                    <div class="form-group">
                        <label for="name" class="control-label col-sm-2 col-sm-offset-2">姓名:</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" v-model="user.name" placeholder="请输入姓名" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="age" class="control-label col-sm-2 col-sm-offset-2">年龄:</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="age" v-model="user.age" placeholder="请输入年龄" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="email" class="control-label col-sm-2 col-sm-offset-2">邮箱:</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="email" v-model="user.email" placeholder="请输入邮箱" />
                        </div>
                    </div>
                    <div class="form-group text-center">
                        <input type="button" name="" id="" value="添 加" class="btn btn-primary" v-on:click="adduser()" />
                        <input type="reset" name="" id="" value="重 置" class="btn btn-primary" />
                    </div>
    
                </form>
                <table class="table table-bordered table-hover">
                    <caption class="h3 text-center">用户列表</caption>
                    <thead>
                        <tr>
                            <th>序号</th>
    
                            <td>姓名</td>
    
                            <th>年龄</th>
    
                            <td>邮箱</td>
    
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(user,index) in users">
                            <td>{{index+1}}</td>
                            <td>{{user.name}}</td>
                            <td>{{user.age}}</td>
                            <td>{{user.email}}</td>
                            <td class="text-right">
                                <button class="btn btn-danger btn-sm" data-toggle="modal" data-target="#del" v-on:click="nowIndex=index">删除</button>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="5" class="text-right">
                                <button class="btn btn-danger btn-sm" data-toggle="modal" data-target="#del" v-on:click="nowIndex=-1">删除所有</button>
                                <button @click="print($event)">click me</button>
                            </td>
                        </tr>
                    </tbody>
    
                </table>
                <div class="modal" id="del">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button class="close" data-dismiss="modal">
                                    <span>
                                    &times;
                                    </span>
                                </button>
                                <h4 class="modal-title" v-show="nowIndex!==-1">确认删除用户:{{users[nowIndex]?users[nowIndex].name:''}}吗?</h4>
                                <h4 class="modal-title" v-show="nowIndex===-1">确认删除所有用户吗?</h4>
                            </div>
                            <div class="modal-body text-center">
                                <button class="btn btn-primary" data-dismiss="modal" v-on:click="deluser()">确定</button>
                                <button class="btn btn-primary" data-dismiss="modal">取消</button>
    
                            </div>
                        </div>
                    </div>
                </div>
            </div>        
        </body>
    
    </html>
  • 相关阅读:
    vue脚手架引入MD5加密函数
    mysql 使用 MD5函数 校验账号密码
    iview引用自定义的图标
    vue 生命周期钩子
    mysql: show processlist 详解
    vue脚手架中动态引用图片的办法
    jsp 获取后端配置文件.properties的某个配置内容
    mybatis update 返回值
    python_判断缩写
    python_深拷贝与浅拷贝
  • 原文地址:https://www.cnblogs.com/yueyue-love/p/8064488.html
Copyright © 2011-2022 走看看