kyy
2025-02-11 bb05da47c66341aa5d65c965528271d03f37a1e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!-- MainPage.vue -->
<template>
  <view>
    <button @click="openSubPage('SubPage')">打开子页面1</button>
    <button @click="openSubPage('SubPage2')">打开子页面2</button>
    <view v-if="showSubPage">
      <component :is="currentComponent" v-bind="componentProps"></component>
    </view>
  </view>
</template>
 
<script>
import SubPage from './SubPage.vue';
import SubPage2 from './SubPage2.vue';
 
export default {
  data() {
    return {
      showSubPage: false,
      currentComponent: null,
      componentProps: {}
    };
  },
  methods: {
    openSubPage(page) {
      if (page === 'SubPage') {
        this.currentComponent = SubPage;
        this.componentProps = { param1: '值1', param2: '值2' };
      } else if (page === 'SubPage2') {
        this.currentComponent = SubPage2;
        this.componentProps = { paramA: '值A', paramB: '值B' };
      }
      this.showSubPage = true;
    }
  }
}
</script>
 
<style scoped>
/* 添加一些样式 */
</style>