当前位置: 首页 > news >正文

按钮样式统一

子组件

<template><div class="btn_box"><div :class="['btn',classType]"><slot name="btn"></slot></div></div>
</template><script setup>
import { computed, useAttrs } from 'vue';
defineOptions({// 定义组件选项,设置inheritAttrs为false,表示不自动将属性绑定到根元素上inheritAttrs: false
});let attrs = useAttrs();// 使用useAttrs()获取组件的属性
const classTypeList = ['primary', 'success', 'info', 'warning', 'danger'];// 定义一个包含所有可能类型的数组const classType = computed(() => {// 计算属性,用于根据传入的type属性返回对应的class类型let lowType = attrs.type.toLowerCase()    // 将type属性转换为小写if(!classTypeList.includes(lowType)) return 'info'    // 如果type属性不在classTypeList数组中,则返回'info'return lowType    // 否则返回type属性的小写形式
})</script><style lang="scss" scoped>
$btnClass: ('primary', 'success', 'info', 'warning', 'danger');
$btnColors: #409eff, #67c23a, #909399, #e6a23c, #f56c6c;
@for $i from 1 through length($btnColors) {$ClasStyle:nth($btnClass, $i);.btn_box{cursor: pointer;@extend .center;}.btn{border-radius: 10px;padding: 10px 15px;}.btn.#{$ClasStyle}{$color: nth($btnColors, $i);background: $color;color: #fff;&:hover{background: lighten($color: $color, $amount:10%);}&:active{background: darken($color: $color, $amount:10%);}&:disabled{background: lighten($color: $color, $amount:20%);color: lighten($color: $color, $amount:40%);}}
}
.center{display: flex;justify-content: center;align-items: center;
}
</style>

父组件

<template><Btnview :type="'primary'"><template v-slot:btn><div>998877</div></template></Btnview></template><script lang="ts" setup name="login">const Btnview = defineAsyncComponent(()=>import('../../components/button/button.vue'));//引入按钮组件</script>``<style lang="less" scoped>
</style>
http://www.xdnf.cn/news/392221.html

相关文章:

  • Kids A-Z安卓版:儿童英语启蒙的优质选择
  • 特励达力科LeCroy推出Xena Freya Z800 800GE高性能的800G以太网测试平台
  • LLM 论文精读(四)LLM Post-Training: A Deep Dive into Reasoning Large Language Models
  • 基于多层权重博弈与广播机制的仿生类脑 AI 决策框架
  • 组合模式(Composite Pattern)详解
  • FR2012A富芮坤ADC:频繁调用adc_get_data要延时
  • 使用lldb看看Rust的HashMap
  • 三、c语言练习四题
  • Linux网络编程实现FTP服务器
  • 探秘 Cursor 核心:解锁系统提示词的进阶之路
  • c++ 如何写类(不带指针版)
  • k8s 资源对比总结
  • 精讲C++四大核心特性:内联函数加速原理、auto智能推导、范围for循环与空指针进阶
  • vue数据可视化开发echarts等组件、插件的使用及建议-浅看一下就行
  • 什么是硬件中断请求号?什么是中断向量号?
  • 英语复习笔记 1
  • Nipype使用:从安装配置到sMRI处理
  • 基于OpenCV的人脸识别:LBPH算法
  • MySQL数据库的安全性防护
  • 【问题】Watt加速github访问速度:好用[特殊字符]
  • 在 C++中,指针数组与数组指针的区别
  • 0基础 | L298N电机驱动模块 | 使用指南
  • 【基于 LangChain 的异步天气查询5】多轮对话天气智能助手
  • js的基本数据类型
  • opencascade.js stp vite 调试笔记
  • 使用 Java 反射动态加载和操作类
  • Ollama部署使用以及模型微调和本地部署
  • go语言对Cookie的支持
  • el-date-picker的type为daterange时仅对开始日期做限制
  • 【Java】线程实例化 线程状态 线程属性