参考文档-vue3
参考文档-arco.design
参考文档-ruoyi
<div v-for="item of AIcons" :key="item" @click="handleClipboard(generateAIconCode(item), $event)">
<a-tooltip placement="top">
<template #content>
{{ generateAIconCode(item) }}
</template>
<div class="icon-item">
<functional-icons :icon="item"></functional-icons>
<span>icon-{{ item }}</span>
</div>
</a-tooltip>
</div>
<script>
import clipboard from '@/utils/clipboard'
import AIcons from './a-icons'
import FunctionalIcons from './FunctionalIcons'
export default {
name: 'Icon',
components: { FunctionalIcons },
setup() {
// tooltip 提示内容
const generateAIconCode = (symbol) => {
return `<icon-${symbol} />`
}
// 复制功能
const handleClipboard = (text, event) => {
clipboard(text, event)
}
return {
AIcons,
generateAIconCode,
handleClipboard
}
}
}
</script>
FunctionalIcons.vue
函数式组件进行组件渲染
<script >
import { h, resolveDynamicComponent } from "vue"
function Icon(props, ctx) {
const Component = resolveDynamicComponent('icon-' + props.icon)
return h(Component)
}
export default Icon
</script>
a-icon.js
将icon名字整合到文件中,并暴露出去
const AIcons = ["loop",......]
export default AIcons