Vue.js+Bootstrap,小练习todoList

前端开发工作总结范文大全 web前端开发师工作注意 外包前端开发工程师合同

html 代码

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <title>vue-Todolist小练</title>
    <link rel=”stylesheet” href=”https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css”>
    <style>
        .def{
background: #000000;
background: -moz-linear-gradient(top, #000000 0%, #ffffff 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#000000), color-stop(100%,#ffffff));
background: -webkit-linear-gradient(top, #000000 0%,#ffffff 100%);
background: -o-linear-gradient(top, #000000 0%,#ffffff 100%);
background: -ms-linear-gradient(top, #000000 0%,#ffffff 100%);
background: linear-gradient(to bottom, #000000 0%,#ffffff 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=’#000000′, endColorstr=’#ffffff’,GradientType=0 );
border-color: white;
color: white;
outline: none;
}
.def:hover{
color: #fff;
background-color: #269abc;
border-color: white;
}
.form-control{
width: 30%;
}
.text-center{
width: 100px;
}
</style>
</head>
<body>
    <div class=”container”>
        <form>
            <div class=”form-group”>
                <label for=”exampleInputEmail1″>职业</label>
                <input type=”text” class=”form-control” v-model=”someThing” id=”exampleInputEmail1″ placeholder=”请输入你的职位”>
            </div>
            <div class=”form-group”>
                <label for=”exampleInputPassword1″>工作年限</label>
                <input type=”text” class=”form-control” v-model=”wordTime” id=”exampleInputPassword1″ placeholder=”请输入工作年限”>
            </div>
            <div class=”form-group”>
                <input type=”button” class=”btn btn-info def” @click=”add()” value=”添加”>
                <input type=”button” class=”btn btn-info def” v-on:click=”again()” value=”重新来”>
            </div>
        </form>
        <table class=”table table-bordered table-hover”>
            <caption style=”color: black;font-weight: bolder”>职业信息表</caption>
            <tr class=”text-danger”>
                <td class=”text-center”>编号</td>
                <td class=”text-center”>职业</td>
                <td class=”text-center”>年限</td>
                <td class=”text-center”>功能</td>
            </tr>
            <tr v-for=”(item,idx) in mayDatas”>
                <td class=”text-center”>{{idx+1}}</td>
                <td class=”text-center”>{{item.position}}</td>
                <td class=”text-center”>{{item.time}}</td>
                <td v-show=”mayDatas.length!==0″ class=”text-center”>
                    <button class=”btn btn-success btn-sm” @click=”del(idx)” data-toggle=”dialog” data-target=”#layer”>删除</button>
                </td>
            </tr>
            <tr>
                <td colspan=”4″ class=”text-right”>
                    <button class=”btn btn-warning btn-sm” @click=”delAll()”>删除全部</button>
                </td>
            </tr>
            <tr v-if=”show”>
                <td colspan=”4″ class=”text-center”>
                    <p>没添加肯定没数据啊,亲</p>
                </td>
            </tr>
            <tr v-if=”hide”>
                <td colspan=”4″ class=”text-center”>
                    <p>已经有数据了</p>
                </td>
            </tr>
        </table>
    </div>
    <script src=”http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js”></script>
    <script src=”https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js”></script>
    <script src=”https://unpkg.com/vue/dist/vue.js”></script>
    <script>
        var MyPc = new vue({
            el: ‘.container’,
            data: {
                mayDatas: [],
                someThing: ”,
                wordTime: ”,
                show: true,
                hide: false
            },
            filters: { //这是过滤器 习惯写上这个了 这里可以忽略
            },
            methods: {
                add: function () {
                    if (!this.someThing) {
                        alert(“请输入职位!”);
                        return false
                    }
                    if (!this.wordTime) {
                        alert(“请输入工作年限!”);
                        return false
                    }
                    if (isNaN(this.wordTime)) {
                        alert(‘工作年限请输入数字!’);
                        return false
                    } else {
                        this.mayDatas.push({ //改变的东东添加到数组
                            position: this.someThing,
                            time: this.wordTime,
                        });
                    }
                    this.show = false;
                    this.hide = true;
                    this.someThing = ”; //添加完后以前的清空
                    this.wordTime = ”
                },
                again: function () {
                    this.someThing = ”;
                    this.wordTime = ”
                },
                del: function (index) {
                    this.mayDatas.splice(index, 1)
                },
                delAll: function () {
                    this.mayDatas = [];
                },
            }
        })
    </script>
</body>
</html>

java开发和前端开发工程师 h5前端开发工程师简历 h5前端开发工程师简历

» 本文来自:前端开发者 » 《Vue.js+Bootstrap,小练习todoList》
» 本文链接地址:https://www.rokub.com/5699.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!