How to use component props or data
Easy. Instead of defining metaInfo
as an object, define it as a function and access this
as usual:
Post.vue:
<template>
<div>
<h1>{{ title }}</h1>
</div>
</template>
<script>
export default {
name: 'post',
props: ['title'],
data () {
return {
description: 'A blog post about some stuff'
}
},
metaInfo () {
return {
title: this.title,
meta: [
{ vmid: 'description', name: 'description', content: this.description }
]
}
}
}
</script>
PostContainer.vue:
<template>
<div>
<post :title="title"></post>
</div>
</template>
<script>
import Post from './Post.vue'
export default {
name: 'post-container',
components: { Post },
data () {
return {
title: 'Example blog post'
}
}
}
</script>
当前内容版权归 nuxtjs.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nuxtjs.org .