2017-06-06 127 views
0

在一個組件中,我正在更改掛載()中的標題和描述,但是我想創建一個全局函數,所以我可以重用下面的代碼。Vuejs 2創建一個全局函數並傳遞參數

我該如何做到這一點?

window.document.title = 111;        
document.head.querySelector('meta[name=description]').content = 222; 

function getTitle(title){ 
    return window.document.title = title; 
} 

回答

3

我發現這個解決方案:

Vue.mixin({ 
    methods: { 
     makeTitle: function (title) { 
      return window.document.title = title; 
     } 
    } 
}); 


export default{ 
    props: ['slug'], 
    data: function() { 
     return { 
      items: [], 
     } 
    }, 
    mounted() { 
     this.makeTitle(this.slug); 
    }, 
相關問題