0
点赞
收藏
分享

微信扫一扫

【Vue】按钮组件(Vue2JS版)- STButton

伢赞 2022-09-13 阅读 353


使用

import STButton from '@/components/STButton'

<STButton>我是默认</STButton>
<STButton type="primary" size="large">我是主要</STButton>
<STButton type="danger" size="small" @click="handle">我是危险</STButton>

效果

【Vue】按钮组件(Vue2JS版)- STButton_背景色

代码

<template>
<button class="st-btn" @click="clickHandler" :class="[typeClass, sizeClass]">
<slot></slot>
</button>
</template>

<script>export default {
name: 'STButton',
props: {
type: {
type: String,
validator: function(val) {
return ['primary', 'danger'].includes(val)
}
},
size: {
type: String,
validator: function(val) {
return ['small', 'large'].includes(val)
}
},
},
computed: {
typeClass(){
return `st-btn-${this.type}`
},
sizeClass(){
return `st-btn-${this.size}`
}
},
methods: {
clickHandler(e){
this.$emit('click', e)
}
}

}</script>

<style scoped lang="less">// 默认背景色 默认大小
.st-btn {
line-height: 1.499;
position: relative;
display: inline-block;
font-weight: 400;
white-space: nowrap;
text-align: center;
background-image: none;
box-shadow: 0 2px 0 rgba(0, 0, 0, 0.015);
cursor: pointer;
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
touch-action: manipulation;
padding: 5px 10px;
font-size: 14px;
border-radius: 4px;
color: rgba(0, 0, 0, 0.65);
background-color: #fff;
border: 1px solid #d9d9d9;
}
.st-btn:focus {
outline: 0;
}
// primary 确定样式
.st-btn-primary {
color: #fff;
background-color: #1890ff;
border-color: #1890ff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);
box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);
}
// danger 危险样式
.st-btn-danger {
color: #fff;
background-color: #ff4d4f;
border-color: #ff4d4f;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);
box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);
}

// size:small
.st-btn-small {
padding: 4px 8px;
font-size: 12px;
}
// size:large
.st-btn-large {
padding: 6px 12px;
font-size: 16px;
}</style>


举报

相关推荐

0 条评论