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

相关标签: # vue.js# html# less# webkit
使用
import STButton from '@/components/STButton'
<STButton>我是默认STButton>
<STButton type="primary" size="large">我是主要STButton>
<STButton type="danger" size="small" @click="handle">我是危险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>
文章来源: https://blog.51cto.com/u_14184703/5673291
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报