我正在尝试动态导入组件,但我的所有组件和vuex变量似乎都未定义。
function loadChart(chartName){
let chart = chartName + '.vue'
return System.import('@/components/charts/' + chart)
}
export default {
name: "SingleChart",
data() {
return {
chartTitle: this.$store.getters.getSingleChartTitle,
chartName: this.$store.getters.getSingleChartName
}
},
methods: {},
computed: {},
watch: {},
props: [],
components: {
Chart: () => loadChart(this.chartName)
}
}
我收到错误
Reason: Error: Cannot find module './undefined.vue'.
答案 0 :(得分:-1)
基于the Vuex state page,您可能没有注入商店以便在您引用时使用它(此。$ store ...)
Vuex提供了一种机制来注入"使用store选项从root组件存储到所有子组件(由Vue.use(Vuex)启用):
const app = new Vue({
el: '#app',
// provide the store using the "store" option.
// this will inject the store instance to all child components.
store,
components: { Counter },
template: `
<div class="app">
<counter></counter>
</div>
})