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