vue3新功能-Teleport

1.teleport  在组件内的任何位置渲染内容

将一个组件内部的一部分模板“传送”到该组件的 DOM 结构外层的位置去。

例:将组件dialog添加到body下面

<teleport to="body">   <el- dialog -->    </teleport> 

2.fragments  多个根元素外层不需要包裹

<fragment>    

<div>11</div>

<div>22</div>

</fragment>

3.render 函数渲染组件视图

通过函数实现以上模板语法

render() {
    return h('div', [
      h('button', { on: { click: this.toggleText } }, 'Toggle Text'),
      h('div', { style: { display: this.showText ? 'block' : 'none' } }, this.text)
    ]);
  }

4. 自定义指令

例子: 聚焦

<template>
  <div>
    <input v-auto-focus />
  </div>
</template>

directives: {
    autoFocus: {
      mounted(el) {
        el.focus();
      }
    }
  }

5. suspense 异步组件加载等待过程中,优先显示一些其他的内容


<template>
  <div>
    <Suspense>
      <template #default> 
//<template #default>这层包裹可去掉
        <AsyncComponent />
      </template>
      <template #fallback>
        <div>Loading...</div>
      </template>
    </Suspense>
  </div>

import { defineAsyncComponent } from 'vue';
const AsyncComponent = defineAsyncComponent(() => import('./AsyncComponent.vue'));

6. Provide/Inject 父子孙...通信

//父
import { provide } from 'vue';
provide('tosunFunc', tosunData);

//子孙
import { inject } from 'vue';
const tosunData = inject('tosunFunc')

相关推荐

  1. Vue3teleport如何使用

    2024-03-17 09:32:02       29 阅读
  2. Vue 3Teleport 组件实现跨层级通信

    2024-03-17 09:32:02       5 阅读
  3. VUE2模拟VUE3中的Teleport实现改变元素挂载的节点

    2024-03-17 09:32:02       36 阅读
  4. Vue TeleportVue的介绍

    2024-03-17 09:32:02       38 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-17 09:32:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-17 09:32:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-17 09:32:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-17 09:32:02       18 阅读

热门阅读

  1. tesseract ocr 安装/调用/训练

    2024-03-17 09:32:02       19 阅读
  2. 基于单片机的电梯系统模拟与研究

    2024-03-17 09:32:02       17 阅读
  3. 音乐软件开发的C#编程思路与实现

    2024-03-17 09:32:02       19 阅读
  4. 【uniapp】uniapp的安卓apk图标角标设置消息数量

    2024-03-17 09:32:02       17 阅读
  5. 有向图的DFS(c++题解)

    2024-03-17 09:32:02       21 阅读
  6. three.js工厂点击动画、标签

    2024-03-17 09:32:02       23 阅读
  7. 贝叶斯定理,先验信念,似然,后验概率

    2024-03-17 09:32:02       27 阅读
  8. Hadoop基础架构及其特点解析

    2024-03-17 09:32:02       18 阅读
  9. C#编程语言在软件开发中的深度应用与实践

    2024-03-17 09:32:02       20 阅读
  10. C语言初阶测试

    2024-03-17 09:32:02       20 阅读
  11. DNS服务

    DNS服务

    2024-03-17 09:32:02      19 阅读