手动实现一个公共vue组件

本文介绍了一个自定义的iOS风格Switch Button组件实现。该组件通过Vue.js进行开发,并使用了SCSS样式来完成动画效果和状态变化。代码示例中详细展示了如何通过点击事件改变开关的状态并触发回调。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现了一个iphone上常见的siwtchbutton组件按钮,废话少说 直接看代码

<template lang="html">
    <div class="button_switch" :class="{change_to_open: open}">
        <div class="circel_button" :class="{trans_to_right: open}" @click="changeType"></div>
    </div>
</template>
<script type="text/ecmascript-6">
    export default{
        name: 'switchbutton',
        props: ['open'],
        methods: {
            changeType() {
                console.log(this.newMsgRemind);
                console.log(this.open);
                let code = this.open ? 1 : 0;
                this.$emit('changeType', code);
                // this.$store.commit(types.SET_CURRENT_CHANNEL_SESSION_NEW_MSG_REMIND, code);
                // console.log(this.open);
                // this.$api.ModifyNewMsgRemindConfig(this.$store.getters.currentChannelId, code);
            }
        }
    };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .button_switch {
        background-color: #fff;
        display: flex;
        justify-content: center;
        border-radius: 100px;
        border: 2px solid #E5E5E5;
        width: 40px;
        height: 28px;
        position: relative;
        /*top: -5px;*/
        box-sizing: border-box;
        .circel_button{
            transition: all .3s;
            position: absolute;
            z-index: 1;
            top: 2px;
            left:1px;
            width: 20px;
            height: 20px;
            background: #FFFFFF;
            box-shadow: 0 0 4px 0 rgba(0,0,0,0.20);
            border-radius: 50%;
            cursor: pointer;
        }
        .trans_to_right{
            transform: translateX(13px);
        }
    }
    .change_to_open{
        background: #4DD865;
    }
</style>

  

转载于:https://www.cnblogs.com/WhiteHorseIsNotHorse/p/7133343.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值