在Vue組件化開發過程中,因為是單頁面開發,但是有時候需要頁面的title根據情況改變,于是上網查了一下,各種說法花(wo)里(kan)胡(bu)哨(dong), 于是想到一個黑科技 documet.title="xxx";
隨便創建一個項目,在獨立的模塊中,created在鉤子函數啟動之后document.title='標題'; 但是據說在IOS的微信下是無效的,雖然用蘋果機測試過有用,但是想到這樣會影響我的代碼潔癖。
<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')); //實例化參數在組件中頂部添加一段 <div v-wechat-title="$route.meta.title"></div>
即可實現改變title效果。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
|
新聞熱點
疑難解答