业务需求,进入页面的时候,网页有个默认标题,加载的网页内容不同时,标题需要变更. 例:功能授权,功能授权(张三).
Vue下有很多的方式去修改网页标题,这里总结下解决此问题的几种方案:
一、最笨方案
结合业务直接在Vue生命周期函数 created 和 mounted 中,给 document.title赋值。
<script>import axios from axiosexport default {created () {document.title = 功能授权},mounted() {axios.get(***).then((d)=>{document.title = 功能授权(+ d.Name + )})}}</script>
二、普通方案,使用Vue-Router的beforeEach拦截
项目中使用了Vue Router,在路由文件 index.js 中给需要的路由添加 title。
routes: [{path: /,name: home,component: () =>