svg图标改用resolveComponent
This commit is contained in:
parent
a403c21924
commit
93c291a668
@ -1,13 +1,9 @@
|
|||||||
<template>
|
|
||||||
<svg :class="svgClass" aria-hidden="true" v-if="iconType == 0">
|
|
||||||
<use :xlink:href="iconName" :fill="color" />
|
|
||||||
</svg>
|
|
||||||
<el-icon v-else><component :is="iconName" /></el-icon>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { h, resolveComponent } from 'vue'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
|
// svg 图标组件名字
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
@ -17,33 +13,37 @@ export default defineComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
// svg 颜色
|
||||||
color: {
|
color: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
return {
|
if (props.name?.startsWith('ele')) {
|
||||||
iconType: computed(() => {
|
return () =>
|
||||||
if (props.name.startsWith('ele')) {
|
h(
|
||||||
return 1
|
'i',
|
||||||
|
{
|
||||||
|
class: 'el-icon',
|
||||||
|
},
|
||||||
|
[h(resolveComponent(props.name.replace('ele-', '')))],
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
return 0
|
return () =>
|
||||||
}
|
h(
|
||||||
}),
|
'svg',
|
||||||
iconName: computed(() => {
|
{
|
||||||
if (props.name?.startsWith('ele-')) {
|
name: props.name,
|
||||||
return props.name.replace('ele-', '')
|
'aria-hidden': true,
|
||||||
} else {
|
style: `color: ${props.color}`,
|
||||||
return `#icon-${props.name}`
|
class: 'svg-icon',
|
||||||
}
|
},
|
||||||
}),
|
h('use', {
|
||||||
svgClass: computed(() => {
|
'xlink:href': `#icon-${props.name}`,
|
||||||
if (props.className) {
|
fill: `${props.color}`,
|
||||||
return `svg-icon ${props.className}`
|
|
||||||
}
|
|
||||||
return 'svg-icon'
|
|
||||||
}),
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -67,8 +67,7 @@ const childrenMenus = computed(() => {
|
|||||||
router.children[item].path = '/redirect/' + router.children[item].path
|
router.children[item].path = '/redirect/' + router.children[item].path
|
||||||
} else {
|
} else {
|
||||||
if (!isHttp(router.children[item].path)) {
|
if (!isHttp(router.children[item].path)) {
|
||||||
router.children[item].path =
|
router.children[item].path = router.path + '/' + router.children[item].path
|
||||||
router.path + '/' + router.children[item].path
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
router.children[item].parentPath = router.path
|
router.children[item].parentPath = router.path
|
||||||
@ -125,7 +124,7 @@ function handleSelect(key, keyPath) {
|
|||||||
window.open(key, '_blank')
|
window.open(key, '_blank')
|
||||||
} else if (key.indexOf('/redirect') !== -1) {
|
} else if (key.indexOf('/redirect') !== -1) {
|
||||||
// /redirect 路径内部打开
|
// /redirect 路径内部打开
|
||||||
router.push({ path: key.replace("/redirect", "") }).catch(err => {});
|
router.push({ path: key.replace('/redirect', '') }).catch((err) => {})
|
||||||
} else {
|
} else {
|
||||||
// 显示左侧联动菜单
|
// 显示左侧联动菜单
|
||||||
activeRoutes(key)
|
activeRoutes(key)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user