<template>
<component :is="currentComponent"></component>
</template>
<script>
export default {
data() {
return {
currentComponent: null,
};
},
created() {
this.loadComponent();
},
methods: {
async loadComponent() {
// 模拟从 Java 后端获取路径
const vueFilePath = await this.getVueComponentPathFromBackend();
// 动态导入 Vue 组件
const component = await import(`./${vueFilePath}`);
// 设置当前组件
this.currentComponent = component.default;
},
getVueComponentPathFromBackend() {
// 这里模拟从 Java 后端获取路径,实际情况你可能需要通过 API 请求获取
return new Promise((resolve) => {
setTimeout(() => {
resolve('components/Example.vue'); // 返回示例路径
}, 1000);
});
},
},
};
</script>