Teleport——Vue3项目中的传入,传送门

为什么会有Teleport的出现?那是因为写组件有的时候真的很繁琐,而且一个项目有可能有很多弹框或者其它公用的模块。如果是跟操作一个DOM一样方便,倒是省事了不少。这个时候,我们想起来vue2有一个PortalVue组件,这妥妥的是vue2年代的好用工具,正如该项目在git上的描述一样“A Portal Component for Vuejs, to render DOM outside of a component, anywhere in the document.”。

回顾PortalVue

安装:

npm i portal-vue

# or

yarn add portal-vue

引用:

import PortalVue from 'portal-vue'
Vue.use(PortalVue)

引用的vue中要告诉整个项目引入到什么地方,如下


  

This slot content will be rendered wherever the with name 'destination' is located.

接收这个portal


  
                    

你可能感兴趣的:(JavaScript,vue.js,vue)