2. 创建一个按钮组件

news/2025/3/11 15:20:14/文章来源:https://www.cnblogs.com/terry841119/p/18765126
在deepseek中输入:
创建一个vue组件
组件实现button的功能
预设4种颜色,分别对应:success: 绿色,危险按钮:红色,警告按钮:橘色,信息按钮:灰色
预设几个带icon的按钮,分别是:搜索,确定,取消,删除,上一页,下一页,分享,编辑
需要让调用该组件是可以自定义一些属性:尺寸,是否圆角,是否禁用,是否有icon

 

deepseek返回的代码:
首先是组件的代码:
<template><buttonclass="custom-button":class="[
      typeClass,sizeClass,{ 'is-round': isRound },{ 'has-icon': icon }]"
    :disabled="disabled"@click="handleClick"><span v-if="icon" class="icon-wrapper"><svgv-if="iconType"class="button-icon"viewBox="0 0 24 24":style="{ width: iconSize, height: iconSize }"><path :d="currentIcon" /></svg></span><span class="button-content"><slot></slot></span></button>
</template><script setup>
import { defineProps, computed } from 'vue'const props = defineProps({type: {type: String,default: 'default',validator: (value) => ['success','danger','warning','info','default'].includes(value)},size: {type: String,default: 'medium',validator: (value) => ['small', 'medium', 'large'].includes(value)},isRound: {type: Boolean,default: false},disabled: {type: Boolean,default: false},icon: {type: String,validator: (value) => ['search','confirm','cancel','delete','prev','next','share','edit'].includes(value)}
})// 图标映射表
const iconMap = {search: 'M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z',confirm: 'M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z',cancel: 'M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z',delete: 'M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z',prev: 'M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z',next: 'M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z',share: 'M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92s2.92-1.31 2.92-2.92c0-1.61-1.31-2.92-2.92-2.92zM18 4c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zM6 13c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm12 7.02c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1z',edit: 'M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34a.9959.9959 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'
}// 计算属性
const typeClass = computed(() => `button-${props.type}`)
const sizeClass = computed(() => `button-${props.size}`)
const iconSize = computed(() => {return {small: '14px',medium: '16px',large: '18px'}[props.size]
})
const currentIcon = computed(() => iconMap[props.icon] || '')
</script><style scoped>
.custom-button {display: inline-flex;align-items: center;justify-content: center;padding: 8px 16px;font-size: 14px;border: 1px solid #ddd;border-radius: 4px;cursor: pointer;transition: all 0.3s ease;
}/* 颜色类型 */
.button-success {background-color: #67c23a;color: white;
}
.button-danger {background-color: #f56c6c;color: white;
}
.button-warning {background-color: #e6a23c;color: white;
}
.button-info {background-color: #909399;color: white;
}/* 尺寸 */
.button-small {padding: 6px 12px;font-size: 12px;
}
.button-medium {padding: 8px 16px;font-size: 14px;
}
.button-large {padding: 10px 20px;font-size: 16px;
}/* 圆角 */
.is-round {border-radius: 20px;
}/* 禁用状态 */
.custom-button:disabled {opacity: 0.6;cursor: not-allowed;
}/* 图标相关 */
.has-icon {gap: 6px;
}
.button-icon {fill: currentColor;
}
</style>

 

然后deepseek还返回了一个组件的引用代码
<template><div><!-- 基础按钮 --><CustomButton type="success">确定</CustomButton><CustomButton type="danger">删除</CustomButton><!-- 带图标按钮 --><CustomButton type="info" icon="search">搜索</CustomButton><CustomButton type="warning" icon="edit">编辑</CustomButton><!-- 自定义属性 --><CustomButton type="success" size="large" :isRound="true" icon="confirm">提交</CustomButton><!-- 禁用状态 --><CustomButton type="danger" :disabled="true">禁用按钮</CustomButton></div>
</template><script setup>
import CustomButton from './components/CustomButton.vue'
</script>

 

当然我们需要对代码进行一些修改,比如组件名我们可以重命名一下
然后也有一些bug
比如icon的显示,这里引用一个我们不曾定义的iconType在if语句里(v-if="iconType"),简单的处理就是我们可以把这句删除
<svgv-if="iconType"class="button-icon"viewBox="0 0 24 24":style="{ width: iconSize, height: iconSize }"><path :d="currentIcon" /></svg>

 

然后运行,我们就可以看到deepseek给我们写的这个组件了
 
0
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/897285.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MySQL:CentOS 7 Docker 联网安装 MySQL

1. 创建mysql挂载目录 mkdir -p /home/data/mysql/config/ 配置目录挂载 mkdir -p /home/data/mysql/data/ 数据目录挂载 2. 在config目录下创建字符集文件 vim /home/data/mysql/config/my.cnf 填写 [mysqld] user=mysql character-set-server=utf8 [client] default-ch…

项目经理私藏!2025年10款小众但超实用的管理神器

在项目管理的江湖中,15 年的实战经验就像是一本活的百科全书,见证了无数项目的起起落落。想象一下,在一个大型建筑项目中,原本计划有序的施工突然因为材料供应不及时而陷入混乱,工期眼看着就要延误,成本也开始失控。这时候,一位经验丰富的项目经理凭借着他独特的管理工具…

SQLServer 死锁排查

适用于2012及以上版本一、创建扩展事件会话 CREATE EVENT SESSION [Deadlock_Monitor] ON SERVER ADD EVENT sqlserver.xml_deadlock_report ADD TARGET package0.event_file(SET filename=NDeadlock_Monitor.xel) WITH (STARTUP_STATE=ON); GO ALTER EVENT SESSION [Deadloc…

Eureka服务注册发现源码流程简析

一: 服务的注册客户端通过执行InstanceInfoReplicator#run()调用DiscoveryClient#register()发送http请求进行注册 InstanceInfoReplicator 是同于更新同步当前服务到服务端的任务实现 //A task for updating and replicating the local instanceinfo to the remote server.//…

高等数学笔记

唉...本蒟蒻也是要考研了, 目前目标是深圳大学, 想研究的方向偏算法多一点, 深度学习强化学习什么的, 我会尽最大努力了 9 做到一个新的问题,想起与过去某个问题类似。发现在解答中,对此类问题,以及工具和方法的理解是存在缺陷的,或者发现理解不够深刻。于是通过解决新的…

Scatter(A Distance-Guided Fuzzing For Heap-layout)

SCATTER Abstract 利用堆利用的方法为将受害者的chunk放在可以溢出的chunk之后。SCATTER使能够以无原始的方式以普通purpose程序中的堆溢出产生可剥削的堆布局。它先使用静态分析和动态检测来计算潜在的堆利用布局,然后设计由新操纵距离为指导的fuzz,该距离衡量了在堆布局空间…

使用 Pixi.js 插件实现探险者小游戏(二)

使用 Pixi.js 插件实现探险者小游戏(一)中我们学习了如何创建精灵图,这节我们要让精灵图动起来。 精灵图布局 游戏画面如下图所示,我们要生成一个围墙,探险者、恶魔、宝物都在这个围墙里面。探险者可以上下左右移动,恶魔只能上下移动,宝物是不动的。探险者与宝物被恶魔群…

Docker:CentOS 7 离线安装 docker-ce

0. 检查卸载已有docker 查看是否安装 docker yum list installed | grep docker 卸载docker yum remove docker docker-common container-selinux docker-selinux docker-engineyum remove -y docker-* 1. 下载安装包 要下载docker-18.06.x-ce版本,否则有些不支持 k8s。。请看…

dp泄露攻击

题目: from Crypto.Util.number import *flag = bNSSCTF{******} + b1*100p = getPrime(512) q = getPrime(512)n = p*q e = 65537 d = inverse(e, (p-1)*(q-1))dp = d % (p-1)m = bytes_to_long(flag)c = pow(m, e, n)print(fn = {n}) print(fc = {c}) print(fdp = {dp}) n = …

dpdq泄露攻击-没e_

题目: from Crypto.Util.number import * from gmpy2 import * from secret import flagp = getPrime(1024) q = getPrime(1024) d = inverse(65537,(p-1)*(q-1)) dp = d%(p-1) dq = d%(q-1) print(fc={pow(bytes_to_long(flag),e,p*q)}) print(fp={p}) print(fq={q}) print(fd…

Linux安装Ollama服务

背景 Ollama官方提供了一键式安装脚本,但因国内网络问题,效率太低,所以探索更为快捷方式。 我的系统信息如下 root@yan:/mnt/d/data# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.5 LTS Release: 22.04 Code…

C学习笔记-311

多维数组和指针 为什么需要数组为了解决大量同类型数据的存储和使用问题。 用数组可以模拟现实世界。Int a[25]:一维数组,可以当做一个线性结构。 Int a[8][6]:可以当做一个平面,意思是8行6列。有48个元素。 Int a[3][4][5]:可以当做一个三维立体。 Int a[3][4][5][6]:可…