[英]Passing props from page layout through parent slot into child component
我有一个Card
组件,在通过<Cards></Cards>
组件的插槽后,我想从父布局中定义的<Card />
标记的title
属性继承title
值。
卡:
<template>
<div class="card">
{{ title }}
</div>
</template>
<script lang="ts">
import Component from 'nuxt-class-component'
import Vue from 'vue'
import { Prop } from 'vue-property-decorator'
@Component
export default class extends Vue {
@Prop() title: string
}
</script>
牌:
<template>
<div class="cards">
<slot></slot>
</div>
</template>
页:
<template>
<Cards>
<Card :title="ABC" />
</Cards>
</template>
我不太确定如何引用title
属性。 这个用Vue怎么写?
您应该能够通过在Card
组件中定义title
属性来做到这一点:
卡:
<template>
<div class="card">
{{ title }}
</div>
</template>
<script>
export default {
props: ['title']
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.