我有這個代碼來呈現我的主屏幕。我想根據從vuex商店獲得的值渲染組件。
一切都很好。當發生變異時,組件不能重新加載的問題。有小費嗎?
<template>
<component v-bind:is = "showDashboard" > </component>
</template>
<script>
import AllOrganizationDashboard from "../components/AllOrganizationDashboard"
import OrganizationDashboard from "../components/OrganizationDashboard"
import ProjectDashboard from "../components/ProjectDashboard"
export default {
components: {
AllOrganizationDashboard,OrganizationDashboard,ProjectDashboard,
},
data(){
return {
showDashboard: this.$store.getters.getcurrentDashboardToShow,
}
}
}
我希望有一個簡單的方法,我不需要re-structure我的組件。
您必須使用computed而不是data,因為創建組件時數據只執行一次。這應該管用
有關計算的詳細信息