vue实现弹出框内嵌页面展示,添加tab切换展示实时加载

最近做业务的时候,发现产品的原型图上有一个弹出框,上面包含了两个窗口要进行切换。
在这里插入图片描述

每个窗口都有分页列表展示、搜索、添加和删除,感觉就是两个完整的页面,如果全写在一个页面会很麻烦,还可能会出现一系列的问题,后期改起来比较麻烦,所以我就准备分开来写这个窗口,先写两个页面,最后看能不能嵌入到弹出框里。
这里插入一下vue的页面跳转方法,点击按钮直接跳转到另一个页面,这样可以先调整单个页面的样式和功能。

<el-table-column label="字典类型" align="center" :show-overflow-tooltip="true">
  <template slot-scope="scope">
    <router-link :to="'/system/dict-data/index/' + scope.row.dictId" class="link-type">
      <span>{{ scope.row.dictType }}</span>
    </router-link>
  </template>
</el-table-column>

参数获取:

created() {
    const dictId = this.$route.params && this.$route.params.dictId;
    this.getType(dictId);
    this.getTypeList();
  },

而且这块跳转的页面也是需要配置路由的,要不然页面就会404:

  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },

当两个页面的功能都实现好了之后,开始在主页面添加弹出框,实现内嵌页面。
在这里插入图片描述

  • 属性变量props: [‘agentId’],该参数用于父子组件传值
  • 组件创建即created的时候,赋值请求后台加载数据

在父页面中引入子页面:
在这里插入图片描述
添加弹出框,内嵌子页面

<el-dialog :title="filterTitle" :visible.sync="filterDialogVisible" v-if="filterDialogVisible" width="1100px"
      append-to-body>
  <el-tabs v-model="filterTabValue" type="border-card" :lazy="true" @tab-click="filterTabClick">
    <el-tab-pane label="内容1" name="hotel">
      <!--  酒店过滤页面    -->
      <HotelFilter :agentId="agentId" v-if="isHotel"></HotelFilter>
    </el-tab-pane>
    <el-tab-pane label="内容2" name="keyword">
      <Keyword :agentId="agentId" v-if="isKeyword"></Keyword>
    </el-tab-pane>
  </el-tabs>
</el-dialog>

父页面通过弹框并将子页面通过引入组件的方式包裹在弹框内,通过:visible.sync=“filterDialogVisible” v-if="filterDialogVisible"进行弹框的展示以及组件的创建和销毁,并且通过父子组件传参的方式切换数据。注意这里需要使用v-if以便子组件可以在create()中动态展示数据。
同理,tabs切换也是通过v-if来控制动态渲染页面。

//设置页面
filterRuleAdd(row) {
  this.agentId = row.agentId;
  this.filterDialogVisible = true;
  this.filterTitle = "渠道名称:" + row.agentName;
  this.filterTabValue = "hotel";
  this.isHotel = true;
},
//禁用配置切换
filterTabClick() {
  if (this.filterTabValue == "hotel") {
    this.isHotel = true;
    this.isKeyword = false;
  } else if (this.filterTabValue == "keyword") {
    this.isKeyword = true;
    this.isHotel = false;
  }
},

参考文档:https://www.jb51.net/article/267510.htm

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue.js 中的延时加载(lazy loading)或延迟加载弹出框通常用于优化用户体验,特别是对于那些在用户滚动到页面底部或其他特定位置才会显示的内容。这样可以减少初始页面加载时间,提高首屏渲染速度。 在 Vue实现这样的功能,你可以使用以下方法: 1. **动态组件**:你可以创建一个懒加载组件,当满足条件(如用户滚动到底部或点击按钮)时才实例化它。例如,使用 `v-if` 和 `v-show` 组件条件: ```html <template> <div> <button @click="showModal">Load Modal</button> <transition-group v-if="showModal"> <lazy-component :is-loaded="modalLoaded" /> </transition-group> </div> </template> <script> export default { data() { return { showModal: false, modalLoaded: false, }; }, methods: { closeModal() { this.modalLoaded = false; this.showModal = false; }, handleLoad() { // 这里处理实际的加载操作,如从 API 获取数据 // 假设 `loadModal` 是异步操作 this.loadModal().then(() => { this.modalLoaded = true; }); }, }, }; </script> ``` 2. **Intersection Observer API**:利用浏览器的 Intersection Observer API 可以监听元素是否进入视口,当元素达到预设条件时触发加载Vue 提供了 vue-observe-visibility 插件来简化使用。 ```html <template> <div> <button @click="showModal">Load Modal</button> <lazy-modal :is-visible="isVisible" /> </div> </template> <script> import LazyModal from 'vue-observe-visibility'; export default { components: { LazyModal, }, data() { return { showModal: false, }; }, mounted() { this.$observeVisibility('.lazy-modal', { rootMargin: '0px', threshold: 0.5, // 视图覆盖度,0.5 表示一半进入可视区域 }).then((data) => { this.isVisible = data.isIntersecting; }); }, methods: { handleLoad() { this.loadModal(); }, }, }; </script> ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值