mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
commit
9d8b680ec5
@ -106,7 +106,7 @@ pages
|
|||||||
```
|
```
|
||||||
|
|
||||||
**需要注意的是,满足以下任意规则的文件不会被注册为路由**:
|
**需要注意的是,满足以下任意规则的文件不会被注册为路由**:
|
||||||
- 不是 `.vue` 文件
|
- 不是 `.vue .jsx` 文件
|
||||||
- `components` 目录中的文件
|
- `components` 目录中的文件
|
||||||
|
|
||||||
|
|
||||||
@ -184,7 +184,12 @@ const router = new VueRouter({
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
在 Fes.js 里约定在 `.vue`单文件组件中的 `config`区块 为 `meta` 配置。如果 `pages/a.vue` 中有如下配置:
|
|
||||||
|
接下来我们来配置 `meta`:
|
||||||
|
|
||||||
|
<CodeGroup>
|
||||||
|
<CodeGroupItem title="vue" active>
|
||||||
|
|
||||||
```vue
|
```vue
|
||||||
<config>
|
<config>
|
||||||
{
|
{
|
||||||
@ -193,6 +198,33 @@ const router = new VueRouter({
|
|||||||
}
|
}
|
||||||
</config>
|
</config>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</CodeGroupItem>
|
||||||
|
<CodeGroupItem title="jsx">
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import { defineRouteMeta, useRoute } from '@fesjs/fes';
|
||||||
|
defineRouteMeta({
|
||||||
|
name: "store",
|
||||||
|
title: "vuex测试"
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</CodeGroupItem>
|
||||||
|
<CodeGroupItem title="tsx">
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
import { defineRouteMeta, useRoute } from '@fesjs/fes';
|
||||||
|
defineRouteMeta({
|
||||||
|
name: "store",
|
||||||
|
title: "vuex测试"
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</CodeGroupItem>
|
||||||
|
</CodeGroup>
|
||||||
|
|
||||||
|
|
||||||
则编译后的路由配置为:
|
则编译后的路由配置为:
|
||||||
```js{5-8}
|
```js{5-8}
|
||||||
[
|
[
|
||||||
|
@ -76,6 +76,16 @@ export default {
|
|||||||
|
|
||||||
## 配置
|
## 配置
|
||||||
|
|
||||||
|
### keep-alive
|
||||||
|
从 4.0.7 开始支持配置路由页面缓存:
|
||||||
|
```
|
||||||
|
<config lang="json">
|
||||||
|
{
|
||||||
|
"keep-alive": true
|
||||||
|
}
|
||||||
|
</config>
|
||||||
|
```
|
||||||
|
|
||||||
### 编译时配置
|
### 编译时配置
|
||||||
在 `.fes.js` 中配置:
|
在 `.fes.js` 中配置:
|
||||||
```js
|
```js
|
||||||
|
@ -184,7 +184,12 @@ const router = new VueRouter({
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
在 Fes.js 里约定在 `.vue`单文件组件中的 `config`区块 为 `meta` 配置。如果 `pages/a.vue` 中有如下配置:
|
|
||||||
|
接下来我们来配置 `meta`:
|
||||||
|
|
||||||
|
<CodeGroup>
|
||||||
|
<CodeGroupItem title="vue" active>
|
||||||
|
|
||||||
```vue
|
```vue
|
||||||
<config>
|
<config>
|
||||||
{
|
{
|
||||||
@ -193,6 +198,33 @@ const router = new VueRouter({
|
|||||||
}
|
}
|
||||||
</config>
|
</config>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</CodeGroupItem>
|
||||||
|
<CodeGroupItem title="jsx">
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import { defineRouteMeta, useRoute } from '@fesjs/fes';
|
||||||
|
defineRouteMeta({
|
||||||
|
name: "store",
|
||||||
|
title: "vuex测试"
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</CodeGroupItem>
|
||||||
|
<CodeGroupItem title="tsx">
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
import { defineRouteMeta, useRoute } from '@fesjs/fes';
|
||||||
|
defineRouteMeta({
|
||||||
|
name: "store",
|
||||||
|
title: "vuex测试"
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</CodeGroupItem>
|
||||||
|
</CodeGroup>
|
||||||
|
|
||||||
|
|
||||||
则编译后的路由配置为:
|
则编译后的路由配置为:
|
||||||
```js{5-8}
|
```js{5-8}
|
||||||
[
|
[
|
||||||
|
@ -76,6 +76,16 @@ export default {
|
|||||||
|
|
||||||
## 配置
|
## 配置
|
||||||
|
|
||||||
|
### keep-alive
|
||||||
|
从 4.0.7 开始支持配置路由页面缓存:
|
||||||
|
```
|
||||||
|
<config lang="json">
|
||||||
|
{
|
||||||
|
"keep-alive": true
|
||||||
|
}
|
||||||
|
</config>
|
||||||
|
```
|
||||||
|
|
||||||
### 编译时配置
|
### 编译时配置
|
||||||
在 `.fes.js` 中配置:
|
在 `.fes.js` 中配置:
|
||||||
```js
|
```js
|
||||||
|
@ -36,7 +36,14 @@
|
|||||||
</keep-alive>
|
</keep-alive>
|
||||||
</router-view>
|
</router-view>
|
||||||
</template>
|
</template>
|
||||||
<router-view v-else></router-view>
|
<router-view v-else v-slot="{ Component, route }">
|
||||||
|
<keep-alive :include="keepAlivePages">
|
||||||
|
<component
|
||||||
|
:is="getComponent(Component, route)"
|
||||||
|
:key="getPageKey(route)"
|
||||||
|
/>
|
||||||
|
</keep-alive>
|
||||||
|
</router-view>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import {
|
import {
|
||||||
@ -144,6 +151,22 @@ export default {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const keepAlivePages = ref([]);
|
||||||
|
const getComponent = (Component, _route) => {
|
||||||
|
if (_route.meta['keep-alive']) {
|
||||||
|
const name = _route.meta?.name || _route.name;
|
||||||
|
if (name) {
|
||||||
|
// 修改组件的 name
|
||||||
|
Component.type.name = name;
|
||||||
|
// 缓存的关键是组件name在keep-alive的include列表
|
||||||
|
if (!keepAlivePages.value.includes(name)) {
|
||||||
|
keepAlivePages.value = [...keepAlivePages.value, name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Component;
|
||||||
|
};
|
||||||
return {
|
return {
|
||||||
route,
|
route,
|
||||||
pageList,
|
pageList,
|
||||||
@ -152,7 +175,9 @@ export default {
|
|||||||
switchPage,
|
switchPage,
|
||||||
handlerMore,
|
handlerMore,
|
||||||
handleCloseTab,
|
handleCloseTab,
|
||||||
actions
|
actions,
|
||||||
|
getComponent,
|
||||||
|
keepAlivePages
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
<config>
|
<config>
|
||||||
{
|
{
|
||||||
"name": "editor",
|
"name": "editor",
|
||||||
"title": "$editor"
|
"title": "$editor",
|
||||||
|
"keep-alive": true
|
||||||
}
|
}
|
||||||
</config>
|
</config>
|
||||||
<script>
|
<script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user