Skip to content

Instantly share code, notes, and snippets.

@cute-angelia
Created April 12, 2022 07:37
Show Gist options
  • Save cute-angelia/75c4979aa1149c4c1a14cdfbb8115309 to your computer and use it in GitHub Desktop.
Save cute-angelia/75c4979aa1149c4c1a14cdfbb8115309 to your computer and use it in GitHub Desktop.
IconFont vue3
<template>
<svg class="icon" aria-hidden="true" :width="fontSize" :height="fontSize">
<use :xlink:href="class" :fill="color"></use>
</svg>
</template>
<script>
import { defineComponent } from "vue";
export default defineComponent({
created() {
let iconfont = document.getElementById("iconfont");
if (!iconfont) {
const s = document.createElement("script");
s.id = "iconfont";
s.type = "text/JavaScript";
s.src = this.scriptUrl;
document.body.appendChild(s);
}
},
props: {
scriptUrl: {
//iconfont上的symbol地址
type: String,
default: "http://at.alicdn.com/t/xxxxxxx.js",
},
class: String, //需要添加的字体图标类
color: {
//图标颜色
type: String,
default: "#444",
},
fontSize: {
//图标大小
type: [String, Number],
default: 16,
},
},
});
</script>
<style scoped>
.icon {
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
}
</style>
<template>
<Iconfont class="#iconpassword" fontSize="20" color="#ccc" />
</template>
<script>
import Iconfont from "@/components/IconFont.vue";
export default {
data() {
return {
};
},
components: {
Iconfont,
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment