a-icon

在Vue应用中,可以使用$confirm方法显示一个对话框,其中的icon可以通过$createElement函数自定义,例如设置为a-icon组件,通过props传入type和theme属性来创建一个填充样式的exclamation-circle图标。

icon 自定义图标(1.14.0 新增) string|()=>VNode
一、利用自带的icon赋值个默认的icon名字就可以了,但是有时候我们需要用到实底风格的icon,所以只能用()=>VNode

this.$confirm({
    title: '确认设置当前位置为出险地点?',
    content: this.infoWindow.contents,
    icon: () => this.$createElement('a-icon', {
        props: {
            type: 'exclamation-circle',
            theme: 'filled'
        },
    }),
    onOk: () => {
        this.onMapClose();
        console.log('点击确认')
    },
    onCancel() {
    },
}); 

### 如何在 Ant Design 中使用 `a-icon` 组件自定义图标 在 Ant Design 的 Vue 实现中,`a-icon` 组件提供了简单的方法来显示内置图标的集合以及支持自定义 SVG 图标。为了实现这一点,开发者可以利用 `<a-icon>` 提供的功能并结合一些额外配置。 对于想要引入自己设计的图标的情况,可以通过注册新的图标类型到全局环境中完成。下面是一个具体的例子说明怎样做到这点: #### 导入必要的模块和支持文件 首先确保安装了 ant-design-vue 和 @ant-design/icons-vue 库,并导入所需的基础包: ```javascript import { createApp } from 'vue'; import App from './App.vue'; // Import Icon definitions import { PlusOutlined, } from '@ant-design/icons-vue'; const app = createApp(App); app.component('PlusOutlined', PlusOutlined); app.mount('#app'); ``` #### 注册和使用自定义SVG图标 如果要添加一个全新的 SVG 文件作为图标资源,则需先将其转换成适合的方式再加载进来。一种方法是通过 JavaScript 动态创建 DOM 节点并将路径数据嵌入其中;另一种更推荐的做法是在项目里设置 Webpack Loader 来处理 `.svg` 文件自动转为 React Component 形式[^1]。 这里给出一段简单的代码片段展示如何声明一个新的名为 "customIcon" 的图标并通过 `a-icon` 使用它: ```html <template> <div id="components-icon-demo-custom"> <!-- Use custom icon --> <a-button type="primary" shape="circle" :icon="customIcon"></a-button> </div> </template> <script setup lang="ts"> import { defineComponent, h } from 'vue'; import { createFromIconfontCN } from '@ant-design/icons-vue'; export default defineComponent({ name: 'CustomIconDemo', components: {}, data() { const customIcon = () => ( h(createFromIconfontCN({ scriptUrl: '//at.alicdn.com/t/font_8d5l8fzk5b87iudi.js' }), 'my-icon-name') ); return { customIcon, }; }, }); </script> ``` 这段代码展示了如何从阿里云字体库获取特定名称 ("my-icon-name") 的图标实例化过程。实际应用时应替换为自己的 URL 及对应的类名或 ID 值。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值