Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue Cli 3 Generated Project Set HTML Title

Currently, after generating a project with Vue CLI 3 the title is "Vue App".

If I set the title in the created hook via document.title the browser will still will flash "Vue App" prior to displaying the title set via document.title.

Looking for a way to set the HTML title for a Vue CLI 3 generated project without it flashing the default "Vue App" title first.

like image 932
xspydr Avatar asked Oct 25 '18 11:10

xspydr


People also ask

How do I change the title of my Vue project?

This can be simply done by changing the content of the <title> tag in our html code. But for Single-Page Applications, things are a little bit different. When the router changes to a different page component, the title should be changed programmatically using document. title = 'new title' .

How do I add Vue to HTML?

The simplest way to get started with Vue is to grab the development version script for it and add it to the head tag of your HTML file. Then you can start Vue code inside the HTML file inside of script tags. And have the Vue code connect up with an existing element on your HTML page.


2 Answers

You can set the title in /public/index.html statically.

Setting it to an empty string in index.html and keeping the update in the hook gets rid of the flashing.

like image 50
wwerner Avatar answered Oct 20 '22 12:10

wwerner


also You can use custom index.html in another way, modify your vue.config.js:


module.exports = {
  publicPath: '/',
  chainWebpack: config => {
    config
      .plugin("html")
      .tap(args => {
        args[0].template = './public/index.html'
        return args
      })
  }
};

like image 23
Pashaman Avatar answered Oct 20 '22 12:10

Pashaman