How do I add a Google Font to a VueJS Component? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30 pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to add some non-standard font to a website?Can I embed a custom font in an iPhone application?How to add multiple font files for the same font?VueJS : using Ckeditor AND Google AnalyticsES6 import using at ('@') sign in path in a vue.js project using Webpackset watcher on props of vuejs componentHow to include js files on a vuejs component?How to include a CDN to VueJS CLI without NPM or Webpack?How do I use other vuejs component directly in my static HTML?Failed to decode downloaded font. OTS parsing error. VueJs

Married in secret, can marital status in passport be changed at a later date?

What *exactly* is electrical current, voltage, and resistance?

What helicopter has the most rotor blades?

Why did Israel vote against lifting the American embargo on Cuba?

When speaking, how do you change your mind mid-sentence?

Preserving file and folder permissions with rsync

What is /etc/mtab in Linux?

Is Bran literally the world's memory?

What is the numbering system used for the DSN dishes?

Determinant of a matrix with 2 equal rows

France's Public Holidays' Puzzle

Will I be more secure with my own router behind my ISP's router?

Test if all elements of a Foldable are the same

Suing a Police Officer Instead of the Police Department

Arriving in Atlanta (after US Preclearance in Dublin). Will I go through TSA security in Atlanta to transfer to a connecting flight?

All ASCII characters with a given bit count

Putting Ant-Man on house arrest

Protagonist's race is hidden - should I reveal it?

Has a Nobel Peace laureate ever been accused of war crimes?

Is it accepted to use working hours to read general interest books?

`FindRoot [ ]`::jsing: Encountered a singular Jacobian at a point...WHY

Why do people think Winterfell crypts is the safest place for women, children & old people?

Why would the Overseers waste their stock of slaves on the Game?

How did Elite on the NES work?



How do I add a Google Font to a VueJS Component?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30 pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to add some non-standard font to a website?Can I embed a custom font in an iPhone application?How to add multiple font files for the same font?VueJS : using Ckeditor AND Google AnalyticsES6 import using at ('@') sign in path in a vue.js project using Webpackset watcher on props of vuejs componentHow to include js files on a vuejs component?How to include a CDN to VueJS CLI without NPM or Webpack?How do I use other vuejs component directly in my static HTML?Failed to decode downloaded font. OTS parsing error. VueJs



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








5















I've been trying for an hour to find a way to import a Google Font into a VueJS Component, but I cannot seem to find a solution, nothing worked yet, not even the stuff from previous StackOverflow questions. All the answers I've found are 1.5 to 2 years old now. I would appreciate it greatly if someone could suggest an up to date solution.



I am using VueJS2 + Webpack + Vue-cli










share|improve this question
























  • You should say what you've tried so far

    – André
    Jul 25 '18 at 10:15











  • I cannot backtrace of what I've tried. I have tried solutions from every blog, stackoverflow, quora question, vuejs that had that topic, but all of them were for VueJS and not VueJS2. Cannot find anything on VueJS2.I'm sure any up to date solution would work

    – Holiday
    Jul 25 '18 at 10:53












  • @André Turns out it was an impossible to see bug all the time that shouldn't be one. Two hours on a bug as usual. Thanks for taking your time to reply Andre.

    – Holiday
    Jul 25 '18 at 10:56






  • 1





    The default @import way described in Google Fonts works fine (check App.vue): codesandbox.io/s/5yyp394zon | Also the <link> way (check index.html): codesandbox.io/s/40v3z6vy3x

    – yuriy636
    Jul 25 '18 at 11:30


















5















I've been trying for an hour to find a way to import a Google Font into a VueJS Component, but I cannot seem to find a solution, nothing worked yet, not even the stuff from previous StackOverflow questions. All the answers I've found are 1.5 to 2 years old now. I would appreciate it greatly if someone could suggest an up to date solution.



I am using VueJS2 + Webpack + Vue-cli










share|improve this question
























  • You should say what you've tried so far

    – André
    Jul 25 '18 at 10:15











  • I cannot backtrace of what I've tried. I have tried solutions from every blog, stackoverflow, quora question, vuejs that had that topic, but all of them were for VueJS and not VueJS2. Cannot find anything on VueJS2.I'm sure any up to date solution would work

    – Holiday
    Jul 25 '18 at 10:53












  • @André Turns out it was an impossible to see bug all the time that shouldn't be one. Two hours on a bug as usual. Thanks for taking your time to reply Andre.

    – Holiday
    Jul 25 '18 at 10:56






  • 1





    The default @import way described in Google Fonts works fine (check App.vue): codesandbox.io/s/5yyp394zon | Also the <link> way (check index.html): codesandbox.io/s/40v3z6vy3x

    – yuriy636
    Jul 25 '18 at 11:30














5












5








5


1






I've been trying for an hour to find a way to import a Google Font into a VueJS Component, but I cannot seem to find a solution, nothing worked yet, not even the stuff from previous StackOverflow questions. All the answers I've found are 1.5 to 2 years old now. I would appreciate it greatly if someone could suggest an up to date solution.



I am using VueJS2 + Webpack + Vue-cli










share|improve this question
















I've been trying for an hour to find a way to import a Google Font into a VueJS Component, but I cannot seem to find a solution, nothing worked yet, not even the stuff from previous StackOverflow questions. All the answers I've found are 1.5 to 2 years old now. I would appreciate it greatly if someone could suggest an up to date solution.



I am using VueJS2 + Webpack + Vue-cli







vue.js fonts vuejs2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 25 '18 at 12:15









Bennett Dams

1,5921419




1,5921419










asked Jul 25 '18 at 10:00









HolidayHoliday

3817




3817












  • You should say what you've tried so far

    – André
    Jul 25 '18 at 10:15











  • I cannot backtrace of what I've tried. I have tried solutions from every blog, stackoverflow, quora question, vuejs that had that topic, but all of them were for VueJS and not VueJS2. Cannot find anything on VueJS2.I'm sure any up to date solution would work

    – Holiday
    Jul 25 '18 at 10:53












  • @André Turns out it was an impossible to see bug all the time that shouldn't be one. Two hours on a bug as usual. Thanks for taking your time to reply Andre.

    – Holiday
    Jul 25 '18 at 10:56






  • 1





    The default @import way described in Google Fonts works fine (check App.vue): codesandbox.io/s/5yyp394zon | Also the <link> way (check index.html): codesandbox.io/s/40v3z6vy3x

    – yuriy636
    Jul 25 '18 at 11:30


















  • You should say what you've tried so far

    – André
    Jul 25 '18 at 10:15











  • I cannot backtrace of what I've tried. I have tried solutions from every blog, stackoverflow, quora question, vuejs that had that topic, but all of them were for VueJS and not VueJS2. Cannot find anything on VueJS2.I'm sure any up to date solution would work

    – Holiday
    Jul 25 '18 at 10:53












  • @André Turns out it was an impossible to see bug all the time that shouldn't be one. Two hours on a bug as usual. Thanks for taking your time to reply Andre.

    – Holiday
    Jul 25 '18 at 10:56






  • 1





    The default @import way described in Google Fonts works fine (check App.vue): codesandbox.io/s/5yyp394zon | Also the <link> way (check index.html): codesandbox.io/s/40v3z6vy3x

    – yuriy636
    Jul 25 '18 at 11:30

















You should say what you've tried so far

– André
Jul 25 '18 at 10:15





You should say what you've tried so far

– André
Jul 25 '18 at 10:15













I cannot backtrace of what I've tried. I have tried solutions from every blog, stackoverflow, quora question, vuejs that had that topic, but all of them were for VueJS and not VueJS2. Cannot find anything on VueJS2.I'm sure any up to date solution would work

– Holiday
Jul 25 '18 at 10:53






I cannot backtrace of what I've tried. I have tried solutions from every blog, stackoverflow, quora question, vuejs that had that topic, but all of them were for VueJS and not VueJS2. Cannot find anything on VueJS2.I'm sure any up to date solution would work

– Holiday
Jul 25 '18 at 10:53














@André Turns out it was an impossible to see bug all the time that shouldn't be one. Two hours on a bug as usual. Thanks for taking your time to reply Andre.

– Holiday
Jul 25 '18 at 10:56





@André Turns out it was an impossible to see bug all the time that shouldn't be one. Two hours on a bug as usual. Thanks for taking your time to reply Andre.

– Holiday
Jul 25 '18 at 10:56




1




1





The default @import way described in Google Fonts works fine (check App.vue): codesandbox.io/s/5yyp394zon | Also the <link> way (check index.html): codesandbox.io/s/40v3z6vy3x

– yuriy636
Jul 25 '18 at 11:30






The default @import way described in Google Fonts works fine (check App.vue): codesandbox.io/s/5yyp394zon | Also the <link> way (check index.html): codesandbox.io/s/40v3z6vy3x

– yuriy636
Jul 25 '18 at 11:30













4 Answers
4






active

oldest

votes


















14














The fastest way is to import the font in a CSS file, for example App.css, if all components should have it:



@import url('https://fonts.googleapis.com/css?family=Roboto+Condensed');

html, body
font-family: 'Roboto Condensed', sans-serif;


#app
font-family: 'Roboto Condensed', sans-serif;



The import statement is also shown by Google Fonts (click on @IMPORT in the selection window):



Google Fonts






share|improve this answer
































    2














    Imo, if you're using VueJS, Google Fonts Webpack Plugin is the way.



    Here's the plugin, it's really easy to set it up and works like a charm.



    npm i google-fonts-webpack-plugin -D



    Go to your /webpack.config.js / webpack.base.config.js and add the following lines:



    const GoogleFontsPlugin = require("google-fonts-webpack-plugin")

    module.exports =
    "entry": "index.js",
    /* ... */
    plugins: [
    new GoogleFontsPlugin(
    fonts: [
    family: "Source Sans Pro" ,
    family: "Roboto", variants: [ "400", "700italic" ]
    ]
    )
    ]



    Now you can use Google Fonts anywhere inside your VueJS project :)






    share|improve this answer






























      1














      I would like to add to the answer given by msqar. If you are going to use Google Fonts Webpack Plugin: (https://www.npmjs.com/package/google-fonts-webpack-plugin )
      and you are using the Vue CLI, you can add a vue.config.js file inside the root of your project. See Vue CLI docs: (https://cli.vuejs.org/guide/webpack.html#simple-configuration)



      Then add the code to that file:



       const GoogleFontsPlugin = require("google-fonts-webpack-plugin");

      module.exports =
      chainWebpack: config =>
      plugins: [
      new GoogleFontsPlugin(
      fonts: [
      family: "Source Sans Pro"
      ]
      )
      ]







      share|improve this answer
































        0














        In Vue2, just @import the font in section inside your vue component



        <style>
        @import url('https://fonts.googleapis.com/css?family=Proza+Libre');
        h1
        font-family: 'Proza Libre', sans-serif;
        color: seagreen;
        font-weight: 300;

        </style>





        share|improve this answer























          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51516084%2fhow-do-i-add-a-google-font-to-a-vuejs-component%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          14














          The fastest way is to import the font in a CSS file, for example App.css, if all components should have it:



          @import url('https://fonts.googleapis.com/css?family=Roboto+Condensed');

          html, body
          font-family: 'Roboto Condensed', sans-serif;


          #app
          font-family: 'Roboto Condensed', sans-serif;



          The import statement is also shown by Google Fonts (click on @IMPORT in the selection window):



          Google Fonts






          share|improve this answer





























            14














            The fastest way is to import the font in a CSS file, for example App.css, if all components should have it:



            @import url('https://fonts.googleapis.com/css?family=Roboto+Condensed');

            html, body
            font-family: 'Roboto Condensed', sans-serif;


            #app
            font-family: 'Roboto Condensed', sans-serif;



            The import statement is also shown by Google Fonts (click on @IMPORT in the selection window):



            Google Fonts






            share|improve this answer



























              14












              14








              14







              The fastest way is to import the font in a CSS file, for example App.css, if all components should have it:



              @import url('https://fonts.googleapis.com/css?family=Roboto+Condensed');

              html, body
              font-family: 'Roboto Condensed', sans-serif;


              #app
              font-family: 'Roboto Condensed', sans-serif;



              The import statement is also shown by Google Fonts (click on @IMPORT in the selection window):



              Google Fonts






              share|improve this answer















              The fastest way is to import the font in a CSS file, for example App.css, if all components should have it:



              @import url('https://fonts.googleapis.com/css?family=Roboto+Condensed');

              html, body
              font-family: 'Roboto Condensed', sans-serif;


              #app
              font-family: 'Roboto Condensed', sans-serif;



              The import statement is also shown by Google Fonts (click on @IMPORT in the selection window):



              Google Fonts







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 9 at 4:02









              Community

              11




              11










              answered Jul 25 '18 at 11:29









              Bennett DamsBennett Dams

              1,5921419




              1,5921419























                  2














                  Imo, if you're using VueJS, Google Fonts Webpack Plugin is the way.



                  Here's the plugin, it's really easy to set it up and works like a charm.



                  npm i google-fonts-webpack-plugin -D



                  Go to your /webpack.config.js / webpack.base.config.js and add the following lines:



                  const GoogleFontsPlugin = require("google-fonts-webpack-plugin")

                  module.exports =
                  "entry": "index.js",
                  /* ... */
                  plugins: [
                  new GoogleFontsPlugin(
                  fonts: [
                  family: "Source Sans Pro" ,
                  family: "Roboto", variants: [ "400", "700italic" ]
                  ]
                  )
                  ]



                  Now you can use Google Fonts anywhere inside your VueJS project :)






                  share|improve this answer



























                    2














                    Imo, if you're using VueJS, Google Fonts Webpack Plugin is the way.



                    Here's the plugin, it's really easy to set it up and works like a charm.



                    npm i google-fonts-webpack-plugin -D



                    Go to your /webpack.config.js / webpack.base.config.js and add the following lines:



                    const GoogleFontsPlugin = require("google-fonts-webpack-plugin")

                    module.exports =
                    "entry": "index.js",
                    /* ... */
                    plugins: [
                    new GoogleFontsPlugin(
                    fonts: [
                    family: "Source Sans Pro" ,
                    family: "Roboto", variants: [ "400", "700italic" ]
                    ]
                    )
                    ]



                    Now you can use Google Fonts anywhere inside your VueJS project :)






                    share|improve this answer

























                      2












                      2








                      2







                      Imo, if you're using VueJS, Google Fonts Webpack Plugin is the way.



                      Here's the plugin, it's really easy to set it up and works like a charm.



                      npm i google-fonts-webpack-plugin -D



                      Go to your /webpack.config.js / webpack.base.config.js and add the following lines:



                      const GoogleFontsPlugin = require("google-fonts-webpack-plugin")

                      module.exports =
                      "entry": "index.js",
                      /* ... */
                      plugins: [
                      new GoogleFontsPlugin(
                      fonts: [
                      family: "Source Sans Pro" ,
                      family: "Roboto", variants: [ "400", "700italic" ]
                      ]
                      )
                      ]



                      Now you can use Google Fonts anywhere inside your VueJS project :)






                      share|improve this answer













                      Imo, if you're using VueJS, Google Fonts Webpack Plugin is the way.



                      Here's the plugin, it's really easy to set it up and works like a charm.



                      npm i google-fonts-webpack-plugin -D



                      Go to your /webpack.config.js / webpack.base.config.js and add the following lines:



                      const GoogleFontsPlugin = require("google-fonts-webpack-plugin")

                      module.exports =
                      "entry": "index.js",
                      /* ... */
                      plugins: [
                      new GoogleFontsPlugin(
                      fonts: [
                      family: "Source Sans Pro" ,
                      family: "Roboto", variants: [ "400", "700italic" ]
                      ]
                      )
                      ]



                      Now you can use Google Fonts anywhere inside your VueJS project :)







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Dec 18 '18 at 14:54









                      msqarmsqar

                      79321948




                      79321948





















                          1














                          I would like to add to the answer given by msqar. If you are going to use Google Fonts Webpack Plugin: (https://www.npmjs.com/package/google-fonts-webpack-plugin )
                          and you are using the Vue CLI, you can add a vue.config.js file inside the root of your project. See Vue CLI docs: (https://cli.vuejs.org/guide/webpack.html#simple-configuration)



                          Then add the code to that file:



                           const GoogleFontsPlugin = require("google-fonts-webpack-plugin");

                          module.exports =
                          chainWebpack: config =>
                          plugins: [
                          new GoogleFontsPlugin(
                          fonts: [
                          family: "Source Sans Pro"
                          ]
                          )
                          ]







                          share|improve this answer





























                            1














                            I would like to add to the answer given by msqar. If you are going to use Google Fonts Webpack Plugin: (https://www.npmjs.com/package/google-fonts-webpack-plugin )
                            and you are using the Vue CLI, you can add a vue.config.js file inside the root of your project. See Vue CLI docs: (https://cli.vuejs.org/guide/webpack.html#simple-configuration)



                            Then add the code to that file:



                             const GoogleFontsPlugin = require("google-fonts-webpack-plugin");

                            module.exports =
                            chainWebpack: config =>
                            plugins: [
                            new GoogleFontsPlugin(
                            fonts: [
                            family: "Source Sans Pro"
                            ]
                            )
                            ]







                            share|improve this answer



























                              1












                              1








                              1







                              I would like to add to the answer given by msqar. If you are going to use Google Fonts Webpack Plugin: (https://www.npmjs.com/package/google-fonts-webpack-plugin )
                              and you are using the Vue CLI, you can add a vue.config.js file inside the root of your project. See Vue CLI docs: (https://cli.vuejs.org/guide/webpack.html#simple-configuration)



                              Then add the code to that file:



                               const GoogleFontsPlugin = require("google-fonts-webpack-plugin");

                              module.exports =
                              chainWebpack: config =>
                              plugins: [
                              new GoogleFontsPlugin(
                              fonts: [
                              family: "Source Sans Pro"
                              ]
                              )
                              ]







                              share|improve this answer















                              I would like to add to the answer given by msqar. If you are going to use Google Fonts Webpack Plugin: (https://www.npmjs.com/package/google-fonts-webpack-plugin )
                              and you are using the Vue CLI, you can add a vue.config.js file inside the root of your project. See Vue CLI docs: (https://cli.vuejs.org/guide/webpack.html#simple-configuration)



                              Then add the code to that file:



                               const GoogleFontsPlugin = require("google-fonts-webpack-plugin");

                              module.exports =
                              chainWebpack: config =>
                              plugins: [
                              new GoogleFontsPlugin(
                              fonts: [
                              family: "Source Sans Pro"
                              ]
                              )
                              ]








                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Dec 26 '18 at 1:23

























                              answered Dec 22 '18 at 21:49









                              Michael HicksMichael Hicks

                              42111




                              42111





















                                  0














                                  In Vue2, just @import the font in section inside your vue component



                                  <style>
                                  @import url('https://fonts.googleapis.com/css?family=Proza+Libre');
                                  h1
                                  font-family: 'Proza Libre', sans-serif;
                                  color: seagreen;
                                  font-weight: 300;

                                  </style>





                                  share|improve this answer



























                                    0














                                    In Vue2, just @import the font in section inside your vue component



                                    <style>
                                    @import url('https://fonts.googleapis.com/css?family=Proza+Libre');
                                    h1
                                    font-family: 'Proza Libre', sans-serif;
                                    color: seagreen;
                                    font-weight: 300;

                                    </style>





                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      In Vue2, just @import the font in section inside your vue component



                                      <style>
                                      @import url('https://fonts.googleapis.com/css?family=Proza+Libre');
                                      h1
                                      font-family: 'Proza Libre', sans-serif;
                                      color: seagreen;
                                      font-weight: 300;

                                      </style>





                                      share|improve this answer













                                      In Vue2, just @import the font in section inside your vue component



                                      <style>
                                      @import url('https://fonts.googleapis.com/css?family=Proza+Libre');
                                      h1
                                      font-family: 'Proza Libre', sans-serif;
                                      color: seagreen;
                                      font-weight: 300;

                                      </style>






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Apr 18 at 14:07









                                      Elisabeth ShevtsovaElisabeth Shevtsova

                                      37638




                                      37638



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51516084%2fhow-do-i-add-a-google-font-to-a-vuejs-component%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          1928 у кіно

                                          Захаров Федір Захарович

                                          Ель Греко