Ant 自定义按钮

AntDesign 自定义Modal组件:移除默认按钮并添加多个操作

Ant design 的 a-modal 去除取消按钮,确定按钮,自定义按钮 或 添加多个按钮

 <a-modal v-model="visible" title="免责声明" :maskClosable="false" :width= "800" :closable="false" >
      <template slot="footer">
        <a-button key="submit" type="primary" @click="handleOk">
          同意声明
        </a-button>
        <a-button key="cancel" type="primary" @click="handlecancel">
          取消
        </a-button>
        <a-button key="other" type="primary" @click="handlecancel">
          其他的
        </a-button>
      </template>
      <p class="respinner"> 

          免责声明内容

      </p>
    </a-modal>

使用

<template slot= 'footer"> 就成功啦

去掉全部底部按钮可直接  :footer=null

Ant Design 的 `Button` 组件中使用自定义图标,可以通过以下几种方式实现,具体取决于你使用的框架(React 或 Vue)以及图标的类型(SVG、字体图标等)。 ### 使用 SVG 图标作为自定义图标 在 React 项目中,可以通过 `@ant-design/icons` 提供的 `Icon` 组件结合 SVG 元素来嵌入自定义 SVG 图标。具体实现如下: ```jsx import { Button } from 'antd'; import { Icon } from '@ant-design/icons'; const CustomIcon = () => ( <Icon component={() => ( <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" > <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" /> </svg> )} /> ); // 在 Button 中使用自定义图标 <Button icon={<CustomIcon />}>自定义图标按钮</Button>; ``` 该方法通过 `component` 属性传递一个返回 SVG 元素的函数,从而实现图标的自定义[^4]。 --- ### 使用字体图标(如阿里巴巴矢量图标库) 如果你使用的是 Ant Design Vue,并希望使用阿里巴巴矢量图标库中的图标作为 `Button` 的图标,可以按照以下方式实现: ```javascript // 引入 Icon 组件 import { Icon } from 'ant-design-vue'; // 创建自定义图标组件 const IconFont = Icon.createFromIconfontCN({ scriptUrl: '//at.alicdn.com/t/font_1848039_k8b44h4qanf.js', // 替换为你的图标库地址 }); // 在组件中使用 export default { components: { IconFont, }, template: ` <a-button> <IconFont type="icon-example" /> <!-- 替换为你需要的图标类型 --> 自定义图标按钮 </a-button> `, }; ``` 该方法通过 `createFromIconfontCN` 创建一个基于字体图标的组件,并在 `Button` 中调用该组件作为图标[^3]。 --- ### 使用 `vue-svg-loader` 引入 SVG 图标 如果你使用的是 Vue 项目,并希望通过 `vue-svg-loader` 引入 SVG 图标,可以按照以下步骤操作: 1. 安装依赖: ```bash npm install -D vue-svg-loader vue-template-compiler ``` 2. 配置 `vue.config.js`: ```javascript module.exports = { chainWebpack: (config) => { config.module .rule('svg') .test(/\.svg$/) .use('vue-svg-loader') .loader('vue-svg-loader'); }, }; ``` 3. 在组件中使用 SVG 图标: ```vue <template> <a-button> <Icon component="MyCustomIcon" /> 自定义图标按钮 </a-button> </template> <script> import MyCustomIcon from '@/assets/icons/custom-icon.svg'; // 引入 SVG 文件 export default { components: { Icon, }, data() { return { MyCustomIcon, }; }, }; </script> ``` 通过 `vue-svg-loader` 可以将 SVG 文件作为 Vue 组件引入,并在 `Button` 中使用自定义图标[^2]。 --- ### 相关问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值