vue2升级vue3:Vue Router报错,directly inside <transition> or <keep-a
vue3 报这个错误:
vue-router.mjs:35 [Vue Router warn]: <router-view> can no longer be used directly inside <transition> or <keep-alive>.
Use slot props instead:
<router-view v-slot="{ Component }">
<keep-alive>
<component :is="Component" />
</keep-alive>
</router-view>
v-slot这种用法在tsx里应该是不能直接这么使用的,毕竟tsx不比模板,写tsx的本质其实是在写渲染函数,于是去翻阅babel-tsx-plugin的文档
最终实现代码:
router
router 页面设置了keep alive
const router = [
{
path: 'dashboards/:folder_uid/:uid',
name: 'dashboard-info',
component: () => import(/* webpackChunkName: "DashboardPreview" */'@/pages/dashboard/dashboard'),
props: route => ({ uid: route.params.uid }),
meta: {
parent: 'dashboard',
},
},
{
path: 'share-panel/:folder_uid/:uid',
name: 'sharePanel',
// component: SharePanel,
components: {
keepAlive: () => import(/* webpackChunkName: "SharePanelPage" */ '../pages/dashboard/dashboard-editor'),
},
meta: {
isHideNav: true,
},
},
]
当然,也可以使用meta 来控制是否 keep-alive。不然过建议用上面的方式实现。
App home 页面
页面路由tsx代码如下:
import { defineComponent, KeepAlive, Transition, Suspense, computed } from 'vue';
import { useRoute, RouterView } from 'vue-router';
import Navigation from '../../components/navigation';
import Loading from '@/components/loading';
export default defineComponent({
name: 'HomePage',
setup() {
const route = useRoute();
const isHideNav = computed(() => {
let { isHideNav } = route.meta;
if (window.location.search.includes('embed')) {
isHideNav = true;
}
return isHideNav;
});
const routeClass = computed(() => {
if (isHideNav.value) {
return 'full-page';
}
return 'flex-1';
});
return () => (
<div class='full-height flex-column'>
{!isHideNav.value && (<Navigation/>)}
<RouterView class={routeClass.value} name='keepAlive'>
{{
default: ({ Component, route }: { Component: () => JSX.Element, route: any }) => (
<KeepAlive>
<Component key={route.meta.usePathKey || route.params.space_uid}/>
</KeepAlive>
),
}}
</RouterView>
<RouterView class={routeClass.value}>
{{
default: ({ Component, route }: { Component: () => JSX.Element, route: any }) => (
<Transition name={route.meta.transition || 'fade'} mode='out-in'>
<Suspense>
{{
default: () => <Component key={route.meta.usePathKey || route.params.space_uid}/>,
fallback: () => <Loading/>,
}}
</Suspense>
</Transition>
),
}}
</RouterView>
</div>
);
},
});
参考链接:
如何在vue3的jsx中使用keep-alive? https://www.zhihu.com/question/467503706
https://如何在tsx中使用vue-router4的keep-alive v-direct.xecus.cc/posts/53167.html
转载本站文章《vue2升级vue3:Vue Router报错,directly inside <transition> or <keep-a》,
请注明出处:https://www.zhoulujun.cn/html/webfront/ECMAScript/vue3/8862.html
vue2升级vue3:Vue Router报错,directly inside <transition> or <keep-a的更多相关文章
- vue router 报错: Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法
参考资料:https://blog.csdn.net/zy21131437/article/details/99548983
- vue router 报错:NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}
https://blog.csdn.net/weixin_43202608/article/details/98884620
- vue2升级vue3:Vue Demij打通vue2与vue3壁垒,构建通用组件
如果你的vue2代码之前是使用vue-class-component 类组件模式写的.选择可以使用 https://github.com/facing-dev/vue-facing-decorator ...
- vue2升级vue3指南(二)—— 语法warning&error篇
本文总结了vue2升级vue3可能会遇到的语法警告和错误,如果想知道怎样升级,可以查看我的上一篇文章:vue2升级vue3指南(一)-- 环境准备和构建篇 Warning 1.deep /deep/和 ...
- vue2升级vue3:vue2 vue-i18n 升级到vue3搭配VueI18n v9
项目从vue2 升级vue3,VueI18n需要做适当的调整.主要是Vue I18n v8.x 到Vue I18n v9 or later 的变化,其中初始化: 具体可以参看:https://vue- ...
- vue2升级vue3:vue-i18n国际化异步按需加载
vue2异步加载之前说过,vue3还是之前的方法,只是把 i18n.setLocaleMessage改为i18n.global.setLocaleMessage 但是本文还是详细说一遍: 为什么需要异 ...
- Vue.js报错Failed to resolve filter问题原因
Vue.js报错Failed to resolve filter问题原因 金刚 vue Vue.js js javascript 之前使用vue.js写分页功能时,写了一个过滤器,发现一个比较奇怪的错 ...
- Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>' ...
- vue IE 报错 引用babel-polyfill
一.vue 项目报错 vuex requires a Promise polyfill in this browser 在网上找到下面三篇文章,然而和我的项目都不太一样. 我的项目基于 基础模 ...
- 【转】Vue项目报错:Uncaught SyntaxError: Unexpected token <
这篇文章主要介绍了Vue项目报错:Uncaught SyntaxError: Unexpected token <,在引入第三方依赖的 JS 文件时,遇到的一个问题,小编觉得挺不错的,现在分享给 ...
随机推荐
- Python 批量合并图片到word文档
这段代码是一个用Python编写的功能,它将指定文件夹中的所有图片插入到Word文档中并保存.以下是代码的主要步骤和功能: 导入必要的库 Python中的docx库用于操作Word文档,glob库用于 ...
- SVN分支与合并透析
做法: 1.拉分支开发代码 2.开发完成后要和到主干去发布,这时候先把主干合并到分支,解决冲突 3.运行分支系统,看是否正确 4.再把该分支合并到主干 要知道分支分出去时的版本号,cmd打开命令行,使 ...
- Upload again!
这道题没做出来,是看题解解出来的 先上传一个.htacess文件用来后面解析jpg格式的木马 再上传木马图片 注意:这里的木马比较特殊,需要为以下这样子的写法,我也不知道为啥 <script l ...
- 一行代码解决IE停用后无法继续使用IE弹窗功能的问题
微软在2023年2月14日通过Edge浏览器更新,彻底封死IE.Windows Update中没有记录.开始菜单中的IE以及桌面IE图标双击自动打开Edge,默认程序设置了IE也没有任何效果,仅能通过 ...
- python的websockets库
安装 pip install websockets 分为客户端和服务端两部分 服务端一般与异步的库一起用 因为客户端不可能只服务一个客户 所以要用异步处理多个客户 以asyncio示例 from we ...
- Web前端工程的装机必备软件
前言 最近作者的电脑 C 盘变红了,这让我很难受(有点小强迫症),所以准备重新安装下系统,顺便把 C 盘扩大点. 注意: 操作系统是 windows 11 23H2. 所有的命令行都是使用 Windo ...
- 倒计时4天!解锁《2023 .NET Conf China》 云原生分会场精彩议程
.NET Conf China 2023 定于 12 月16 日于北京举办为期一天的技术交流,届时会有.NET 领域专家与大家一同庆祝 .NET 8 的发布和回顾过去一年来 .NET 在中国的发展成果 ...
- [ABC270Ex] add 1
Problem Statement You are given a tuple of $N$ non-negative integers $A=(A_1,A_2,\ldots,A_N)$ such t ...
- @Async实现异步任务
1.@Async是SpringBoot自带的一个执行步任务注解 @EnableAsync // 开启异步 @SpringBootApplication public class Application ...
- Python趣味入门10:推倒繁琐化烦为简的推导式
前言 <西部世界>的德洛丽丝进入了MAZE迷宫,假设她需要列出一系列的平方数作为密码,来进入迷宫.在以往的代码生成类似的数列需要使用循环语句,写多行语句.Python有了推导式,只需要1句 ...