parent
9d0972cf79
commit
e191d25b68
3 changed files with 46 additions and 45 deletions
@ -1,54 +1,53 @@ |
||||
<template> |
||||
<!-- svg 渲染本地SVG的静态资源 --> |
||||
<svg :width="size" :height="size" :class="` ${className}` "> |
||||
<use :xlink:href="`#icon-${name}`" ></use> |
||||
</svg> |
||||
<svg :class="svgClass" aria-hidden="true"> |
||||
<use :xlink:href="iconName"></use> |
||||
<title v-if="!!title">{{ title }}</title> |
||||
</svg> |
||||
</template> |
||||
|
||||
<script> |
||||
export default{ |
||||
props:{ |
||||
// SVG 文件名称 |
||||
name:{ |
||||
type:String, |
||||
required:true, |
||||
export default { |
||||
name: 'SvgIcon', |
||||
props: { |
||||
iconClass: { |
||||
type: String, |
||||
required: true |
||||
}, |
||||
// 额外类名 |
||||
className:{ |
||||
type:String, |
||||
default:"", |
||||
className: { |
||||
type: String |
||||
}, |
||||
// SVG 大小 |
||||
size:{ |
||||
type:Number, |
||||
default:50, |
||||
title: { |
||||
type: String, |
||||
default: '' |
||||
} |
||||
}, |
||||
data(){ |
||||
return{ |
||||
|
||||
mounted(){ |
||||
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> |
||||
<style scoped lang="less"> |
||||
|
||||
</style> |
||||
|
||||
<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> |
||||
|
||||
Loading…
Reference in new issue