parent
9d0972cf79
commit
e191d25b68
3 changed files with 46 additions and 45 deletions
@ -1,54 +1,53 @@ |
|||||||
<template> |
<template> |
||||||
<!-- svg 渲染本地SVG的静态资源 --> |
<svg :class="svgClass" aria-hidden="true"> |
||||||
<svg :width="size" :height="size" :class="` ${className}` "> |
<use :xlink:href="iconName"></use> |
||||||
<use :xlink:href="`#icon-${name}`" ></use> |
<title v-if="!!title">{{ title }}</title> |
||||||
</svg> |
</svg> |
||||||
</template> |
</template> |
||||||
|
|
||||||
<script> |
<script> |
||||||
export default{ |
export default { |
||||||
props:{ |
name: 'SvgIcon', |
||||||
// SVG 文件名称 |
props: { |
||||||
name:{ |
iconClass: { |
||||||
type:String, |
type: String, |
||||||
required:true, |
required: true |
||||||
}, |
}, |
||||||
// 额外类名 |
className: { |
||||||
className:{ |
type: String |
||||||
type:String, |
|
||||||
default:"", |
|
||||||
}, |
}, |
||||||
// SVG 大小 |
title: { |
||||||
size:{ |
type: String, |
||||||
type:Number, |
default: '' |
||||||
default:50, |
|
||||||
} |
} |
||||||
}, |
}, |
||||||
data(){ |
mounted(){ |
||||||
return{ |
console.log(8888,this.iconClass) |
||||||
|
}, |
||||||
|
computed: { |
||||||
|
iconName() { |
||||||
|
debugger |
||||||
|
return `#icon-${this.iconClass}` |
||||||
|
}, |
||||||
|
svgClass() { |
||||||
|
if (this.className) { |
||||||
|
return 'svg-icon ' + this.className |
||||||
|
} else { |
||||||
|
return 'svg-icon' |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
// import { computed } from "vue"; |
|
||||||
// const props=defineProps({ |
|
||||||
// // SVG 文件名称 |
|
||||||
// name:{ |
|
||||||
// type:String, |
|
||||||
// required:true, |
|
||||||
// }, |
|
||||||
// // 额外类名 |
|
||||||
// className:{ |
|
||||||
// type:String, |
|
||||||
// default:"", |
|
||||||
// }, |
|
||||||
// // SVG 大小 |
|
||||||
// size:{ |
|
||||||
// type:Number, |
|
||||||
// default:50, |
|
||||||
// } |
|
||||||
|
|
||||||
// }) |
|
||||||
</script> |
</script> |
||||||
<style scoped lang="less"> |
|
||||||
|
|
||||||
|
<style lang="scss" scoped> |
||||||
|
.svg-icon { |
||||||
|
width: 1.1em; |
||||||
|
height: 1.1em; |
||||||
|
margin-left: 0.35em; |
||||||
|
margin-right: 0.35em; |
||||||
|
vertical-align: -0.15em; |
||||||
|
fill: currentColor; |
||||||
|
overflow: hidden; |
||||||
|
} |
||||||
</style> |
</style> |
||||||
Loading…
Reference in new issue