mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-17 01:30:33 +03:00
feat: add possibility to add additional meta info
refactor: server injectors feat: add head, bodyPrepend, bodyAppend injectors refactor: create browserbuild through rollup replace (not separate entry)
This commit is contained in:
+32
-15
@@ -1,26 +1,34 @@
|
||||
import { clientSequences } from '../shared/escaping'
|
||||
import { showWarningNotSupported } from '../shared/log'
|
||||
import { getComponentMetaInfo } from '../shared/getComponentOption'
|
||||
import { getAppsMetaInfo, clearAppsMetaInfo } from '../shared/additional-app'
|
||||
import getMetaInfo from '../shared/getMetaInfo'
|
||||
import { isFunction } from '../utils/is-type'
|
||||
import updateClientMetaInfo from './updateClientMetaInfo'
|
||||
|
||||
export default function refresh (options = {}) {
|
||||
/**
|
||||
* When called, will update the current meta info with new meta info.
|
||||
* Useful when updating meta info as the result of an asynchronous
|
||||
* action that resolves after the initial render takes place.
|
||||
*
|
||||
* Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
|
||||
* to implement this method.
|
||||
*
|
||||
* @return {Object} - new meta info
|
||||
*/
|
||||
/**
|
||||
* When called, will update the current meta info with new meta info.
|
||||
* Useful when updating meta info as the result of an asynchronous
|
||||
* action that resolves after the initial render takes place.
|
||||
*
|
||||
* Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
|
||||
* to implement this method.
|
||||
*
|
||||
* @return {Object} - new meta info
|
||||
*/
|
||||
export default function refresh (vm, options = {}) {
|
||||
// make sure vue-meta was initiated
|
||||
if (!vm.$root._vueMeta) {
|
||||
showWarningNotSupported()
|
||||
return {}
|
||||
}
|
||||
|
||||
// collect & aggregate all metaInfo $options
|
||||
const rawInfo = getComponentMetaInfo(options, this.$root)
|
||||
const rawInfo = getComponentMetaInfo(options, vm.$root)
|
||||
|
||||
const metaInfo = getMetaInfo(options, rawInfo, clientSequences, this.$root)
|
||||
const metaInfo = getMetaInfo(options, rawInfo, clientSequences, vm.$root)
|
||||
|
||||
const appId = this.$root._vueMeta.appId
|
||||
const { appId } = vm.$root._vueMeta
|
||||
const tags = updateClientMetaInfo(appId, options, metaInfo)
|
||||
|
||||
// emit "event" with new info
|
||||
@@ -28,5 +36,14 @@ export default function refresh (options = {}) {
|
||||
metaInfo.changed(metaInfo, tags.addedTags, tags.removedTags)
|
||||
}
|
||||
|
||||
return { vm: this, metaInfo, tags }
|
||||
const appsMetaInfo = getAppsMetaInfo()
|
||||
if (appsMetaInfo) {
|
||||
for (const additionalAppId in appsMetaInfo) {
|
||||
updateClientMetaInfo(additionalAppId, options, appsMetaInfo[additionalAppId])
|
||||
delete appsMetaInfo[additionalAppId]
|
||||
}
|
||||
clearAppsMetaInfo(true)
|
||||
}
|
||||
|
||||
return { vm, metaInfo, tags }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user