1
我有几个组件的应用程序。我使用Vuex来存储数据,所以我可以在不同的组件中使用它。现在我需要使用v-for渲染一些div。我做如下:Vuex。如何从商店使用v-for呈现数据
VueX /模块/ shows.js
const state = {
shows: [
{
name: 'Hard Luck',
venue: 'The Venue',
time: '6:00 pm'
},
{
name: 'Hard Luck',
venue: 'The Venue',
time: '6:00 pm'
}
]
}
export default {
state
}
组件,我需要使用数据:
<template>
<div class="dashboard__details dashboard__details--shows"
v-for="show in shows">
<h3 class="dashboard__name">
{{show.name}} @ {{show.venue}}
</h3>
<span class="dashboard__time">{{show.time}}</span>
<div class="dashboard__btnBlock">
<button">Details</button>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import ReportIssue from './ReportIssue'
import InviteFriend from './InviteFriend'
export default {
name: 'dashboard',
components: { ReportIssue, InviteFriend },
computed: mapState({
shows: state => {
return state.shows
}
})
}
</script>
它的工作原理,如果我有在组件的数据,但我的数据如果我将数据存储在Vuex中,则无法工作。
非常感谢你 –
不用担心,如果它帮助认罪e将其标记为答案 – GuyC