Categories
Vue Answers

How to Set the Page Title Dynamically with Vue.js?

Spread the love

Sometimes, we want to set the page title dynamically with Vue.js.

In this article, we’ll look at how to set the page title dynamically with Vue.js.

Set the Page Title Dynamically with Vue.js

We can set the page title dynamically with Vue.js by setting the document.title property to a string.

For instance, we can write:

<template>  
  <div id="app"></div>  
</template>  
<script>  
export default {  
  name: "App",  
  mounted() {  
    document.title = "page title";  
  },  
};  
</script>

We set the document.title to the string with the title content.

And we should see it at the top of the browser tab.

Conclusion

We can set the page title dynamically with Vue.js by setting the document.title property to a string.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

2 replies on “How to Set the Page Title Dynamically with Vue.js?”

Thanks for reading.

Yes. The code uses the Options API, but Composition API shouldn’t be too different.

Leave a Reply

Your email address will not be published. Required fields are marked *