在 Vue 3 中,可以使用 `` 将 `` 包裹在根 `div` 中。具体步骤如下:

  1. 在根组件中,添加一个 ``,并设置 `to` 属性为 `body`,表示将组件渲染到 `body` 元素中。
  2. 在 `index.html` 中添加一个空的根 `div`,这个 `div` 将会被 `` 渲染到。
  3. 
    
      
        
        My App
      
      
        

这样就可以将 `` 包裹在根 `div` 中了。注意,要使用 Vue 3 的语法,需要安装并使用 `@vue/compiler-sfc` 编译器。

Vue3 中使用 teleport 将 keep-alive 包裹在根 div 中

原文地址: https://www.cveoy.top/t/topic/lNpG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录