[Vuejs]-Does anyone know how to change the web page title while the page is loading without Vue-router?

0πŸ‘

i try many web page,it’s always first show url then 0.1s less show title;

t tnink you can use document.title = xxxxx in your target page

0πŸ‘

It is expected behavior. Let me explain why this happens when you use window.location.href to change url.

When you are not using vue-router to change urls and use window.location.href, the browser makes an http request for the page (index.html) to your server. So, while the http request is fetching the browser does not have any idea about the html of the page and thus does not know the title of the page. So it simply shows the only known thing about the page, that is the URL. When the http request resolves and the javascript and vue initializes, the beforeCreate hook runs and the page title is set to your preference.

When you use vue-router there is no http call to server, all is done using javascript and vue. The title is changed using javascript and vue. No page reload happens.

Hope this helps

Leave a comment