您的位置:首页 > Web前端 > Vue.js

vue-(prop验证-个人名片)

2020-06-11 04:37 197 查看

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>个人名片</title>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

    <style>

        .box {

            /* border: 1px solid red ; */

            width: 530px;

            height: 350px;

            position: relative;

            margin: 0 auto;

            margin-top: 200px;

        }

        .card {

            border: 1px solid rgb(226, 213, 96);

            border-top: 1px solid rgb(248, 241, 186);

            width: 500px;

            height: 310px;

            background-image: url(img/bg.jpg);

            background-size: cover;

            color: gray;

            border-radius: 10px;

            box-shadow: 10px 10px 10px grey;

        }

        img {

            width: 28px;

            height: 28px;

            padding: 2px;

        }

        .one {

            border: 1px solid transparent;

            width: 50px;

            margin-top: 20px;

            margin-left: 290px;

        }

        .two {

            border: 1px solid transparent;

            width: 150px;

            margin-top: -280px;

            float: right;

            margin-right: 10px;

            line-height: 34px;

            color: rgb(31, 30, 22);

            background-color: rgb(252, 251, 248);

            border-radius: 10px;

            font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;

        }

        .left {

            border: 1px solid transparent;

            width: 140px;

            height: 140px;

            margin-top: -220px;

            margin-left: 50px;

            border-radius: 90px;

            background-color: white;

            box-shadow: 10px 10px 10px grey;

        }

        .er {

            width: 80px;

            height: 80px;

            margin-left: 27px;

            margin-top: 11px;

        }

        .p {

            border: 1px solid transparent;

            border-radius: 5px;

            color: rgb(252, 251, 248);

            background-color: rgb(226, 214, 104);

            box-shadow: 10px 10px 10px rgb(163, 163, 162);

        }

        .text {

            margin-left: 32px;

            font-size: 19px;

        }

        .h {

            margin-left: 0px;

            margin-top: -290px;

        }

        .hh {

            width: 45px;

            height: 45px;

        }

    </style>

</head>

<body>

    <div id="app">

        <card :my-name="'zy'" :my-company="'TimiStudioGroup'" :my-position="'(IT部)前端工程师'" :my-phone="'18266668888'"

            :my-email="'12345678@qq.com'">

        </card>

    </div>

    <script>

        Vue.component("card", {

            props: {

                id: [String, Number],

                // 姓名(字符串类型,必须的)

                myName: {

                    type: String,

                    validator: function (value) {

                        var reg = /^[\u4E00-\u9FA5]{2,4}$/;

                        if (reg.test(value)) {

                            return true;

                        }

                        // return false;

                        alert("姓名格式不对!")

                    }

                },

                // 公司(字符串类型,必须的)

                myCompany: {

                    type: String,

                    validator: function (value) {

                        var reg = /^[\u4e00-\u9fa5_a-zA-Z0-9]+$/;

                        if (reg.test(value)) {

                            return true;

                        }

                        // return false;

                        alert("公司格式不对!")

                    }

                },

                // 职位(字符串类型,非必须)

                myPosition: {

                    type: String,

                    validator: function (value) {

                        var reg = /^[\u4e00-\u9fa5\(\)()\da-zA-Z&]{2,50}$/gi;

                        if (reg.test(value)) {

                            return true;

                        }

                        // return false;

                        alert("职位格式不对!")

                    }

                },

                // 手机(字符串类型,要验证)

                myPhone: {

                    type: String,

                    validator: function (value) {

                        var reg = /(^1[3|4|5|7|8|9]\d{9}$)|(^09\d{8}$)/;

                        if (reg.test(value)) {

                            return true;

                        }

                        // return false;

                        alert("手机号格式不对!")

                    }

                },

                // 邮箱(字符串类型,要验证)

                myEmail: {

                    type: String,

                    validator: function (value) {

                        var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;

                        if (reg.test(value)) {

                            return true;

                        }

                        // return false;

                        alert("邮箱格式不对!")

                    }

                }

            },

            template: `

                <div class="box">

                    <div class="card">

                        <div class="one">

                            <p><img src="img/name.png"></p>

                            <p><img src="img/company.png"></p>

                            <p><img src="img/position.png"></p>

                            <p><img src="img/phone.png"></p>

                            <p><img src="img/email.png"></p>

                        </div>

                        <div class="two">

                            <p class="p">{{myName}}</p>

                            <p class="p">{{myCompany}}</p>

                            <p class="p">{{myPosition}}</p>

                            <p class="p">{{myPhone}}</p>

                            <p class="p">{{myEmail}}</p>

                        </div>

                        <div class="left">

                            <p><img src="img/er.png" class="er"></p>

                        </div>

 

                        <div class="text">

                            <p>Welcome to our team .</p>

                        </div>

 

                        <div class="h">

                            <p><img src="img/h.png" class="hh"></p>

                        </div>

                    </div>

                </div>

            `

        })

        var app = new Vue({

            el: "#app",

        })

    </script>

</body>

</html>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: