export type RouteInfo = {
name : string,
title : string,
icon : string,
path : string,
permId : string,
roleId : number,
children : RouteInfo[]
}
export function getRoute() : RouteInfo[] {
const tmpRoute = SysRoutes as RouteInfo[];
// const roleType = getRoleType();
return tmpRoute
}
-- 页面:
<template>
<scroll-view :scroll-y="true" class="home-page">
<scroll-view class="left-route" :scroll-y="true">
<view class="left-oute-item" v-for="(route,index) in routes" :key="index">
<text>{{route.title}}</text>
</view>
</scroll-view>
<scroll-view class="right-route" :scroll-y="true">
</scroll-view>
</scroll-view>
</template>
<script lang="uts">
import { getRoute } from '@/store/routers.uts'
import { RouteInfo } from '@/types/routeInfo'
export default {
data() {
return {
routes: [] as Array<RouteInfo>
}
},
created() {
this.routes = getRoute() as RouteInfo[];
},
onShow() { },
methods: {
}
}
</script>
-- 编译控制台报错:
10:18:49.021 error: java.lang.ClassCastException: io.dcloud.uniapp.vue.UTSReactiveJSONObject cannot be cast to uni.UNI791BB6D.RouteInfo
10:18:49.021 at pages/index/home.uvue:4:3
10:18:49.021 2 | <scroll-view :scroll-y="true" class="home-page">
10:18:49.021 3 | <scroll-view class="left-route" :scroll-y="true">
10:18:49.021 4 | <view class="left-oute-item" v-for="(route,index) in routes" :key="index">
10:18:49.021 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:18:49.021 5 | <text>{{route.title}}</text>
10:18:49.021 6 | </view>
5***@qq.com (作者)
尴尬了,我不知道哪里出了问题,我把RouteInfo[]更改为UTSJSONObject[] 就没报错,在项目中用type类型就报错,而且项目编译特别慢
2024-10-10 11:09
DCloud_UNI_yuhe
回复 5***@qq.com: 你尝试给一下能稳定复现报错的代码
2024-10-10 11:12