馬熙澄 發表於 2020-12-8 19:27:00

vue动态改变标题

<p>在router/index.js写路由的js中添加一段代码:</p>
<div class="cnblogs_code">
<pre>router.beforeEach((to, from, next) =&gt;<span style="color: rgba(0, 0, 0, 1)"> {
const { title } </span>=<span style="color: rgba(0, 0, 0, 1)"> to.meta
</span><span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (title) {
    document.title </span>= `标题 |<span style="color: rgba(0, 0, 0, 1)"> ${title}`
}
next()
})
export </span><span style="color: rgba(0, 0, 255, 1)">default</span> router</pre>
</div>
<p>&nbsp;</p>

</div>
<div id="MySignature" role="contentinfo">
    不要在该奋斗的年纪选择去偷懒,只有度过一段连自己都被感动了的日子,才会变成那个最好的自己.<br><br>
来源:https://www.cnblogs.com/kpengfang/p/14105108.html
頁: [1]
查看完整版本: vue动态改变标题