简体   繁体   English

在 vuetify 中更改默认字体不起作用 (vue-cli 3) [Vuetify 1.X]

[英]Change default font in vuetify is not working (vue-cli 3) [Vuetify 1.X]

I'm aware of the question change-default-font-in-vuetify in SO, but it doesn't address my problem as it was posted before vue-cli-3 came out, so the ideas there don't apply here as that, the official docs from Vuetify on how to change themes and other options don't have any valid step for when the project is created with vue-cli 3.我知道 SO 中的change-default-font-in-vuetify问题,但它没有解决我的问题,因为它是在 vue-cli-3 出现之前发布的,所以那里的想法在这里不适用也就是说, Vuetify 关于如何更改主题和其他选项的官方文档在使用 vue-cli 3 创建项目时没有任何有效步骤。

So far my attempts go like this:到目前为止,我的尝试是这样的:

  • vue create fooproject (using default config, but even if I don't use the default but cherrypick what I want in the project and select the css-preprocessor as stylus manually it won't work) vue 创建 fooproject(使用默认配置,但即使我不使用默认配置,而是在项目中选择我想要的内容并手动选择 css 预处理器作为手写笔,它也不起作用)

  • vue add vuetify vue 添加 vuetify

  • it creates a plugin dir: src/plugins, where it stores vuetify.js它创建了一个插件目录:src/plugins,它存储 vuetify.js

  • add a v-btn in the HelloWorld component just for knowing if the font had effect在 HelloWorld 组件中添加一个 v-btn 只是为了知道字体是否有效

  • Then I should be able to import ../stylus/main.styl, where I have:然后我应该能够导入../stylus/main.styl,我有:

    @import '~vuetify/src/stylus/settings/_variables' $body-font-family = 'Open Sans', sans-serif; @import '~vuetify/src/stylus/settings/_variables' $body-font-family = 'Open Sans', sans-serif; $heading-font-family = 'Montserrat', sans-serif; $heading-font-family = 'Montserrat', sans-serif; @import '~vuetify/src/stylus/main' @import '~vuetify/src/stylus/main'

I even tried with @import '~vuetify/src/stylus/main' , do I have to do also vue add additional stylus-loader dependencies or anything plus?我什至尝试过 @import '~vuetify/src/stylus/main' ,我是否还需要添加额外的 stylus-loader 依赖项或其他任何东西? Because that's exactly what it's NOT recommended on Vuetify's website.因为这正是 Vuetify 网站上不推荐的。

Error log: no errors, I just keep seing Roboto font in my material buttons错误日志:没有错误,我只是在我的材料按钮中看到 Roboto 字体

Any remarks?有什么备注吗?

Other attempts: I tried to follow the steps written by Jacob E. Dawson but I'm missing something super silly probably.其他尝试:我尝试按照Jacob E. Dawson编写的步骤进行操作,但我可能遗漏了一些非常愚蠢的内容。

Edit: the linked article from medium at the time didn't specify it was not scoped to a specific Vue version as of September 2019.编辑:当时来自媒体的链接文章没有指定它不限于截至 2019 年 9 月的特定 Vue 版本。

So I just took a quick and fresh glance back to this, at the end it was something silly, if a project is created with vue-cli 3 (either custom choices or default), then obviously in the component App.vue I had to take out font-family from the style section as it overwrites the CSS: 所以我只是快速地重新审视了这一点,最后它是愚蠢的,如果用vue-cli 3(自定义选项或默认选项)创建项目,那么显然在组件App.vue我不得不从样式部分取出font-family,因为它覆盖了CSS:

#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif; /* this was it */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

EDIT: 编辑:
It's possible that some styles are broken when importing styles from main.styl: 从main.styl导入样式时,某些样式可能会被破坏:
https://github.com/vuetifyjs/vuetify/issues/3583 https://github.com/vuetifyjs/vuetify/issues/3583


Does everything load, do you get any errors? 一切都加载,你有任何错误吗?

It seems it should work, unless perhaps you have some typos somewhere, or incorrect paths? 它似乎应该工作,除非你在某个地方有错误或不正确的路径?
For example stylus should be styles in your @require '~vuetify/src/stylus/main.styl' . 例如stylus应该是styles在你@require '~vuetify/src/stylus/main.styl'

do I have to do also vue add stylus-loader? 我还要做vue添加stylus-loader吗?

It should already be added for you. 它应该已经为您添加了。

If you did not select specific CSS preprocessor (ie stylus) during vue-cli installation, then you need to add it manually 如果在vue-cli安装期间未选择特定的CSS预处理器(即手写笔),则需要手动添加
npm i -S stylus stylus-loader

module: {
  rules: [
    {
      test: /\.styl$/,
      loader: ['style-loader', 'css-loader', 'stylus-loader']
    }
  ]
}

This is working for me using nuxt 2.15.8 .这对我使用nuxt 2.15.8

Add this to your nuxt.config.js将此添加到您的nuxt.config.js

vuetify: {
    treeShake: true,
    defaultAssets: {
      font: {
        family: "Inter",
      },
      icons: "mdi",
    },
}

在此处输入图片说明

If you need different font weights you might have to import them manually in you CSS or as a in your HTML如果您需要不同的字体粗细,您可能需要在 CSS 或 HTML 中手动导入它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM