在Vue組件化開發(fā)過程中,因?yàn)槭菃雾撁骈_發(fā),但是有時候需要頁面的title根據(jù)情況改變,于是上網(wǎng)查了一下,各種說法花(wo)里(kan)胡(bu)哨(dong), 于是想到一個黑科技 documet.title="xxx";
隨便創(chuàng)建一個項(xiàng)目,在獨(dú)立的模塊中,created在鉤子函數(shù)啟動之后document.title='標(biāo)題'; 但是據(jù)說在IOS的微信下是無效的,雖然用蘋果機(jī)測試過有用,但是想到這樣會影響我的代碼潔癖。
<script>export default { data(){ return{ } }, created(){ document.title="首頁" },}</script>于是在github上找到一個好用的東西 vue-wechat-title
通過 npm install vue-wechat-title 安裝
引入需要的vue-router與頁面需要的組件之后
const router = new VueRouter({ mode: 'history', routes:[ { name: 'index', path: '/', meta: { title: '首頁' }, component: index }, { name: 'root', path: '/root', meta: { title: '肉特' }, component: root } ]});Vue.use(require('vue-wechat-title')); //實(shí)例化參數(shù)在組件中頂部添加一段 <div v-wechat-title="$route.meta.title"></div>
即可實(shí)現(xiàn)改變title效果。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持錯新站長站。
新聞熱點(diǎn)
疑難解答
圖片精選