Home >Web Front-end >Vue.js >How to dynamically change title in vuejs

How to dynamically change title in vuejs

青灯夜游
青灯夜游Original
2021-09-26 17:04:563539browse

Method to dynamically change the title: 1. Use "document.title=el.dataset.title" in "main.js" to configure the browser title; 2. In the tag of the page, add "v- title data-title="title value"" code can be changed dynamically.

How to dynamically change title in vuejs

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

Dynamicly modify the page title in the Vue project

In main.js:

// 设置浏览器标题
Vue.directive('title', {
  inserted: function (el, binding) {
    document.title = el.dataset.title
  }
})

On the largest div of a certain page:

How to dynamically change title in vuejs

Add the following code:

v-title data-title="测试title"

Effect:

How to dynamically change title in vuejs

Related recommendations: "vue.js Tutorial"

The above is the detailed content of How to dynamically change title in vuejs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn