- 主应用传入entry到props
const fetchAppProject = () => {
return {
project: '01',
theme: "01",
entry: "/dist-01",
}
}
const containerRef = ref(null)
const microApp = null;
onMounted(() => {
const config = fetchAppProject();
microApp = loadMicroApp({
name: config.project,
entry: config.entry,
container: containerRef.value,
props: {
entry: config.entry,
theme: config.theme
},
})
})
onUnmounted(() => {
microApp && microApp.unmount();
})
- 子应用保存entry
let app = null;
var STATIC_DIR = '';
function render(props) {
console.log('props', props)
app = createApp(App)
app.mount(props?.container ? props?.container.querySelector('#container') : '#container')
STATIC_DIR = props?.entry ? props?.entry : '';
app.config.globalProperties.$STATIC_DIR = STATIC_PATH;
}
- 使用静态资源示例
<van-image :src="`${STATIC_DIR}/static/logo.png`"></van-image>
- vite.config.js 修改 base
export default defineConfig({
base: "dist-01",
build: {
outDir: 'dist-01',
},
})
- 部署目录结构
./main
- assets/
- index.html
- dist-01
- assets/
- index.html