vue实现按钮的相关功能

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Document</title>    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>    <style>        * {            margin: 0;            padding: 0;            list-style: none;        }        .btn {            margin: 30px auto;            font-size: 20px;            border: none;            border-radius: 3px;            outline: none;            width: 100px;            height: 35px;            color: #999;            cursor: pointer;            text-align: center;            /* border: 1px solid #ccc; */        }        .btn.warn {            background: orange;            color: #fff;        }        .btn.success {            background: green;            color: #fff;        }        .btn.primary {            background: blue;            color: #fff;        }        .btn.error {            background: red;            color: #fff;        }         .btn.small {          width: 60px;          height: 25px;          font-size: 14px;        }        .btn.middle {          width: 120px;          height: 50px;          font-size: 20px;        }               .btn.large {          width: 200px;          height: 50px;          font-size: 25px;        }    </style></head><body>    <!-- <slot></slot>    //    插槽 -->    <div id="app">        <btn type='warn' size="samll">登录</btn>        <btn type='success' size="middle">登录</btn>        <btn type='primary' size="large">登录</btn>        <btn type='error'>登录</btn>        <!-- <button class="btn warn">登录</button>   <button class="btn error">登录</button>   <button class="btn primary">登录</button>   <button class="btn success">登录</button> -->    </div>    <script>        Vue.component('btn', {            props:{                type:{                    type:String,                },              size:{                  size:String              }            },            data() {                return {                    c:{                        warn:this.type==='warn',                        error:this.type==='error',                        primary:this.type==='primary',                        success:this.type==='success',                        small:this.size==='small',                        middle:this.size==='middle',                        large:this.size==='large',                                         },                                 }            },            methods: {                       handleClick(e){                           this.$emit('click',e)                       }                   },            template:                ` <button class="btn" :class="c" @click="handleClick">                   <slot></slot>                             </button>                `        })        let vm = new Vue({            el: "#app",            data() {                return {                }            },            methods: {            },        })    </script></body></html>

作者:lylovexz
链接:https://juejin.im/post/6844904186912440328
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值