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:
@@ -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
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user