mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-23 08:00:34 +03:00
add change event
This commit is contained in:
@@ -28,6 +28,10 @@ if (typeof window !== 'undefined' && window !== null) {
|
||||
export default function updateClientMetaInfo (newInfo, $root) {
|
||||
// if this is not a server render, then update
|
||||
if (htmlTag.getAttribute(SERVER_RENDERED_ATTRIBUTE) === null) {
|
||||
// initialize tracked changes
|
||||
const addedTags = {}
|
||||
const removedTags = {}
|
||||
|
||||
// update the title
|
||||
updateTitle(newInfo.title)
|
||||
|
||||
@@ -40,14 +44,18 @@ export default function updateClientMetaInfo (newInfo, $root) {
|
||||
// update tags
|
||||
for (let i = 0, len = tags.length; i < len; i++) {
|
||||
const tag = tags[i]
|
||||
updateTags(tag, newInfo[tag], headTag)
|
||||
const { oldTags, newTags } = updateTags(tag, newInfo[tag], headTag)
|
||||
if (newTags.length) {
|
||||
addedTags[tag] = newTags
|
||||
removedTags[tag] = oldTags
|
||||
}
|
||||
}
|
||||
|
||||
// emit event
|
||||
if (typeof newInfo.changed === 'function') {
|
||||
newInfo.changed(newInfo, addedTags, removedTags)
|
||||
}
|
||||
} else {
|
||||
htmlTag.removeAttribute(SERVER_RENDERED_ATTRIBUTE)
|
||||
}
|
||||
|
||||
// HACK: since we're performing DOM side effects, we can't rely on
|
||||
// Vue.nextTick in our tests. This event helps keep the test suite
|
||||
// free of setTimeout clutter
|
||||
$root.$emit('vue-meta-update')
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export default function getMetaInfo (component) {
|
||||
for (let key in info) {
|
||||
if (info.hasOwnProperty(key)) {
|
||||
const value = info[key]
|
||||
if (typeof value === 'function') {
|
||||
if (typeof value === 'function' && key !== 'changed') {
|
||||
info[key] = value()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user