我正在尝试使用Nuxt,Firebase和Vuetify建立一个应用程序。我是一个新手开发者,希望能得到以下问题的帮助。
我不能添加Google Fonts(最后试过Bellefair)或者改变全局默认字体大小到我的Nuxt与Vuetify项目中。我的 nuxt.config.js
是下面的。另外,我也不能改变默认的字体大小。我已经尝试了各种我找到的片段,但到目前为止似乎都没有成功。我终于找到了下面的方法,但仍然没有成功。
import colors from "vuetify/es5/util/colors";
export default {
mode: "spa",
head: {
titleTemplate: "%s - " + process.env.npm_package_name,
title: process.env.npm_package_name || "",
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{
hid: "description",
name: "description",
content: process.env.npm_package_description || ""
}
],
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }, {
rel: "stylesheet", href:"https://fonts.googleapis.com/css?family=Bangers|Bellefair"
}]
},
loading: "@/components/loading",
css: [],
plugins: ["@/plugins/fireauth.js"],
buildModules: ["@nuxtjs/vuetify"],
modules: [
"@nuxtjs/axios",
"@nuxtjs/pwa",
"@nuxtjs/date-fns"
],
router: {
middleware: "fb-auth"
},
axios: {},
vuetify: {
customVariables: ["~assets/styles/variables.scss"],
theme: {
light: true,
themes: {
dark: {
primary: colors.blue.darken2,
accent: colors.grey.darken3,
secondary: colors.amber.darken3,
info: colors.teal.lighten1,
warning: colors.amber.base,
error: colors.deepOrange.accent4,
success: colors.green.accent3
}
}
}
},
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {}
}
};
而我的 ~assets/styles/variables.scss
文件是。
$body-font-family: "Bellefair", sans-serif;
$font-size-root: 20px;
@font-face {
font-family: "Bellefair";
src: url("https://fonts.googleapis.com/css?family=Bellefair");
}
body {
font-family: "Bellefair", sans-serif;
}
我在nuxt.config中添加了= css: ['~assetsstylesmy-custom-styles.css']到我的nuxt.config.js,并且在该文件中
div {
font-family: "Montserrat", sans-serif;
font-size: 18px;
}
另外,我发现我的nuxt.config.js头不需要样式表链接到googleapis.com。
很抱歉占用了这里的空间,但总是欢迎看到更好的回复......
1. 添加你的谷歌字体嵌入nuxt.config.js中的链接,例如,添加DM Sans字体。
head: {
titleTemplate: '%s - ' + process.env.npm_package_name,
title: process.env.npm_package_name || '',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{
rel: 'stylesheet', href: '<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;700&display=swap" rel="stylesheet"> '
}
] },
2. 在vuetify部分的nuxt.config.js中启用treeshaking。
vuetify: {
customVariables: ['~/assets/variables.scss'],
treeShake: true,
}
3. 添加规则assetsvariable.scss。
$body-font-family : 'DM Sans', sans-serif;