2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-12 12:12:27 +03:00
Files
vue-meta/src/shared/plugin.js
T
2016-11-04 09:32:48 +02:00

36 lines
886 B
JavaScript

import getMetaInfo from './getMetaInfo'
import $meta from '../server/$meta'
import updateClientMetaInfo from '../client/updateClientMetaInfo'
// automatic install
if (typeof Vue !== 'undefined') {
Vue.use(VueMeta)
}
/**
* Plugin install function.
* @param {Function} Vue - the Vue constructor.
*/
export default function VueMeta (Vue) {
// bind the $meta method to this component instance
Vue.prototype.$meta = $meta
// store an id to keep track of DOM updates
let requestId = null
// watch for client side component updates
Vue.mixin({
beforeMount () {
// batch potential DOM updates to prevent extraneous re-rendering
window.cancelAnimationFrame(requestId)
requestId = window.requestAnimationFrame(() => {
requestId = null
// update the meta info
updateClientMetaInfo(getMetaInfo(this.$root))
})
}
})
}