[英]vue.js import a component dynamically
我正在尝试动态导入组件,但是我所有的组件和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'.
根据Vuex状态页 ,您可能没有像参考所引用的那样注入商店以使用它(this。$ store ...)
Vuex提供了一种使用store选项将存储从根组件“注入”到所有子组件的机制(由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>
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.