Files
frost-navigation/src/components/Icon.vue
2021-07-05 23:15:24 +08:00

68 lines
1.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<i class="fn-icon bg-center-contain" :style="iconStyle"></i>
</template>
<script>
export default {
name: 'Icon',
props: {
// 来源inner、outer
from: {
type: String,
default: 'inner'
},
// 路径
// 若为 inner自动添加 @/assets/icon/
path: {
type: String,
default: 'unknown.svg'
},
// 尺寸
size: {
type: String,
default: '1em'
},
// 显示图标
showIcon: {
type: Boolean,
default: true
}
},
computed: {
// 图标样式
iconStyle() {
var style = {
width: this.size,
height: this.size
};
var iconPath = '';
// 不显示图标内容
if (!this.showIcon) {
return style;
}
if (this.from === 'inner') {
// 内部
iconPath = require(`@/assets/icon/${this.path}`);
} else if (this.from === 'outer') {
// 外部
iconPath = this.path;
}
style.backgroundImage = `url('${iconPath}')`;
return style;
}
}
}
</script>
<style lang="less" scoped>
.fn-icon {
display: inline-block;
vertical-align: middle;
font-style: normal;
}
</style>