Vue中修改网页title

在created()方法中修改:

<template>
  <div>
    <h2>我是Profile组件</h2>
  </div>
</template>

<script>
  export default {
    name: "Profile",
    created() {
      console.log('Profile created');
      document.title = '修改标题';
    },
    destroyed() {
      console.log('Profile destroyed');
    }
  }
</script>

<style scoped>

</style>

使用前置路由修改

index.js中:

// 前置守卫(guard)
router.beforeEach((to, from, next) => {
  // 从from跳转到to
  document.title = to.matched[0].meta.title // 修改title
  // console.log(to);
  // console.log('++++');
  next()
})

来源:coderwhy老师

发布了353 篇原创文章 · 获赞 4 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/Xidian2850/article/details/103843383