我有两个组件rad-list和rad-card,我在rad-list中放置了一个插槽元素,我将在其中放置rad-card,现在rad-card需要访问父rad-list组件中的computeResults数据我可以使用Vue插槽访问它吗?
RAD列表
<template>
<div class="RADlist_maincontainer">
<layout-pagination-1 v-show="pagination.last_page > 1" :pagination="pagination" @paginate="paginate({ page:pagination.current_page, paginate:paginate })"></layout-pagination-1>
<div class="RADlist_wrapper">
<!--rad-card, or any other component which will use computedResults GOES HERE-->
<slot></slot>
</div>
<layout-pagination-1 v-show="pagination.last_page > 1" :pagination="pagination" @paginate="paginate({ page:pagination.current_page, paginate:paginate })"></layout-pagination-1>
</div>
</template>
这是我的模板中的样子:
<rad-list model="Discount" module="Discount" results="discounts">
<rad-card :item="result" v-for="result in computedResults" :key="result.id" :model="module"></rad-card>
</rad-list>
我的完整RADlist组件Justi,以备不时之需:
<template>
<div class="RADlist_maincontainer">
<layout-pagination-1 v-show="pagination.last_page > 1" :pagination="pagination" @paginate="paginate({ page:pagination.current_page, paginate:paginate })"></layout-pagination-1>
<div class="RADlist_wrapper">
<!--rad-card, or any other component which will use computedResults GOES HERE-->
<slot></slot>
</div>
<layout-pagination-1 v-show="pagination.last_page > 1" :pagination="pagination" @paginate="paginate({ page:pagination.current_page, paginate:paginate })"></layout-pagination-1>
</div>
</template>
<!--SCRIPTS-->
<script>
import { mapState } from 'vuex';
export default{
name: 'RADlist',
computed:
{
computedResults: function()
{
return this.$store.state[this.module][this.results];
},
pagination: function()
{
return this.$store.state[this.module].pagination;
},
...mapState('Loader', ['loader'])
},
props:
{
component: { default:'rad-card', type:String },
module: { default:'Post', type:String },
action: { default:'list', type:String },
results: { default:'posts', type:String },
page: { default:1, type:Number },
paginate: { default:6, type:Number },
},
mounted()
{
console.log(this.$options.name+' component successfully mounted');
this.$store.dispatch(this.module+'/'+this.action, { page: this.page, paginate: this.paginate, loaderId:2473});
},
}
</script>