mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-23 16:30:34 +03:00
feat: add option waitOnDestroyed
This commit is contained in:
+7
-2
@@ -20,17 +20,22 @@ export default function $meta (options) {
|
||||
'setOptions': (newOptions) => {
|
||||
const refreshNavKey = 'refreshOnceOnNavigation'
|
||||
if (newOptions && newOptions[refreshNavKey]) {
|
||||
options.refreshOnceOnNavigation = newOptions[refreshNavKey]
|
||||
options.refreshOnceOnNavigation = !!newOptions[refreshNavKey]
|
||||
addNavGuards($root)
|
||||
}
|
||||
|
||||
const debounceWaitKey = 'debounceWait'
|
||||
if (newOptions && newOptions[debounceWaitKey]) {
|
||||
if (newOptions && debounceWaitKey in newOptions) {
|
||||
const debounceWait = parseInt(newOptions[debounceWaitKey])
|
||||
if (!isNaN(debounceWait)) {
|
||||
options.debounceWait = debounceWait
|
||||
}
|
||||
}
|
||||
|
||||
const waitOnDestroyedKey = 'waitOnDestroyed'
|
||||
if (newOptions && waitOnDestroyedKey in newOptions) {
|
||||
options.waitOnDestroyed = !!newOptions[waitOnDestroyedKey]
|
||||
}
|
||||
},
|
||||
'refresh': () => refresh($root, options),
|
||||
'inject': () => process.server ? inject($root, options) : showWarningNotSupportedInBrowserBundle('inject'),
|
||||
|
||||
@@ -52,6 +52,9 @@ export const ssrAppId = 'ssr'
|
||||
// How long meta update
|
||||
export const debounceWait = 10
|
||||
|
||||
// How long meta update
|
||||
export const waitOnDestroyed = true
|
||||
|
||||
export const defaultOptions = {
|
||||
keyName,
|
||||
attribute,
|
||||
@@ -59,6 +62,7 @@ export const defaultOptions = {
|
||||
tagIDKeyName,
|
||||
contentKeyName,
|
||||
metaTemplateKeyName,
|
||||
waitOnDestroyed,
|
||||
debounceWait,
|
||||
ssrAppId
|
||||
}
|
||||
|
||||
+16
-9
@@ -147,25 +147,32 @@ export default function createMixin (Vue, options) {
|
||||
},
|
||||
// TODO: move back into beforeCreate when Vue issue is resolved
|
||||
destroyed () {
|
||||
const $this = this
|
||||
// do not trigger refresh:
|
||||
// - when user configured to not wait for transitions on destroyed
|
||||
// - when the component doesnt have a parent
|
||||
// - doesnt have metaInfo defined
|
||||
if (!$this.$parent || !hasMetaInfo($this)) {
|
||||
if (!this.$parent || !hasMetaInfo(this)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Wait that element is hidden before refreshing meta tags (to support animations)
|
||||
const interval = setInterval(() => {
|
||||
if ($this.$el && $this.$el.offsetParent !== null) {
|
||||
/* istanbul ignore next line */
|
||||
this.$nextTick(() => {
|
||||
if (!options.waitOnDestroyed || !this.$el || !this.$el.offsetParent) {
|
||||
triggerUpdate(options, this.$root, 'destroyed')
|
||||
return
|
||||
}
|
||||
|
||||
clearInterval(interval)
|
||||
// Wait that element is hidden before refreshing meta tags (to support animations)
|
||||
const interval = setInterval(() => {
|
||||
if (this.$el && this.$el.offsetParent !== null) {
|
||||
/* istanbul ignore next line */
|
||||
return
|
||||
}
|
||||
|
||||
triggerUpdate(options, $this.$root, 'destroyed')
|
||||
}, 50)
|
||||
clearInterval(interval)
|
||||
|
||||
triggerUpdate(options, this.$root, 'destroyed')
|
||||
}, 50)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isObject } from '../utils/is-type'
|
||||
import { isObject, isUndefined } from '../utils/is-type'
|
||||
import { defaultOptions } from './constants'
|
||||
|
||||
export function setOptions (options) {
|
||||
@@ -17,7 +17,8 @@ export function setOptions (options) {
|
||||
tagIDKeyName: options['tagIDKeyName'] || defaultOptions.tagIDKeyName,
|
||||
contentKeyName: options['contentKeyName'] || defaultOptions.contentKeyName,
|
||||
metaTemplateKeyName: options['metaTemplateKeyName'] || defaultOptions.metaTemplateKeyName,
|
||||
debounceWait: options['debounceWait'] || defaultOptions.debounceWait,
|
||||
debounceWait: isUndefined(options['debounceWait']) ? defaultOptions.debounceWait : options['debounceWait'],
|
||||
waitOnDestroyed: isUndefined(options['waitOnDestroyed']) ? defaultOptions.waitOnDestroyed : options['waitOnDestroyed'],
|
||||
ssrAppId: options['ssrAppId'] || defaultOptions.ssrAppId,
|
||||
refreshOnceOnNavigation: !!options['refreshOnceOnNavigation']
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user