gpt4 book ai didi

javascript - vue.js 动态导入组件

转载 作者:行者123 更新时间:2023-11-28 10:41:42 26 4
gpt4 key购买 nike

我正在尝试动态导入组件,但我所有的组件和 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'.

最佳答案

基于the Vuex state page ,您可能没有像您引用的那样注入(inject)商店来使用它(this.$store...)

Vuex provides a mechanism to "inject" the store into all child components from the root component with the store option (enabled by 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>
})

关于javascript - vue.js 动态导入组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50818295/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com