我有以下 Vue 组件
export default {
components: {
DimensionedImage
},
props: [
'site'
]
}
对象在哪里site
:
{
title: '',
imageUrls: [],
hostname: ''
}
该组件的渲染函数如下所示:
<article>
<header>
<h1>{{this.site.title}}</h1>
</header>
<div class="images-container">
<template v-for="imageUrl in this.site.imageUrls">
<DimensionedImage :key="imageUrl" :url="imageUrl" :hostname="this.site.hostname"/>
</template>
</div>
</article>
如您所见,我想hostname
从site
prop 传递到DimensionedImage
组件中,但 Vue 一直告诉我这this
是未定义的。
有人可以告诉我这里的幕后发生了什么,为什么this
会失去它的背景?然后我如何才能真正修复代码以便我可以传递hostname
到this.site
子组件中?