2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-05-17 05:19:37 +03:00

fix #699: bind component instance to computed metaInfo

This commit is contained in:
pimlie
2021-08-01 20:30:32 +02:00
parent ef3b51a74c
commit 1f22adbce8
3 changed files with 19 additions and 6 deletions
+14 -4
View File
@@ -1,6 +1,16 @@
export default {
metaInfo: {
title: 'Title from Options API'
import { defineComponent } from 'vue'
export default defineComponent({
data () {
return {
title: 'Data Title'
}
},
metaInfo () {
const title = this.title
return {
title: title + ' from Options API'
}
},
template: '<div>This component uses the Options API</div>'
}
})
+1 -1
View File
@@ -21,7 +21,7 @@ export const createMixin: CreateMixin = options => ({
const metaInfo = (instance.type as any)[options.keyName] as ComponentOptionsMetaInfo
if (isFunction(metaInfo)) {
const computedMetaInfo = computed(metaInfo)
const computedMetaInfo = computed(metaInfo.bind(this))
useMeta(computedMetaInfo)
} else {
useMeta(metaInfo)
+4 -1
View File
@@ -1,3 +1,5 @@
import { ComponentOptionsMixin } from 'vue'
export interface AttributeProperty {
[key: string]: string | string[]
}
@@ -129,4 +131,5 @@ export interface ComponentMetaInfo {
noscript?: NoScriptProperty[]
}
export type ComponentOptionsMetaInfo = ComponentMetaInfo | (() => ComponentMetaInfo)
// TODO: how to infer the real component options in this?
export type ComponentOptionsMetaInfo = ComponentMetaInfo | ((this: ComponentOptionsMixin) => ComponentMetaInfo)