【发布时间】:2021-12-12 20:10:10
【问题描述】:
我正在尝试在我的项目中导入 google font。
App.vue
<template>
<div id="app">Luckiest Guy</div>
</template>
<script>
export default {
name: "App",
};
</script>
<style scoped lang="scss">
@import "./assets/scss/main.scss";
#app {
font-family: "Luckiest Guy", "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
main.scss
@import '../fonts/fonts.scss';
字体.scss
@font-face {
font-family: 'Luckiest Guy';
src: url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&display=swap');
}
代码沙盒:
https://codesandbox.io/s/dazzling-frost-2mbuf?file=/src/App.vue
更新 1
我也试过用下载的otf,但是不行
字体.scss
@font-face {
font-family: 'Luckiest Guy';
src: url('<The relative path of the otf>');
}
更新 2
我也试过用下载的otf,但是不行
@font-face { font-family: '最幸运的人'; src: url('./LuckiestGuy-Regular.ttf'); }
代码沙盒:
https://codesandbox.io/s/dazzling-frost-2mbuf?file=/src/assets/fonts/fonts.scss
【问题讨论】:
-
您是否也尝试过其他字体扩展? .woff 或 .woff2。
标签: javascript css vue.js sass fonts