docs: 更新model和access文档

This commit is contained in:
harrywan 2021-12-14 11:42:49 +08:00
parent 0236057c51
commit 0d075f0037
4 changed files with 82 additions and 2 deletions

View File

@ -195,7 +195,7 @@ console.log(access.isDataReady())
- PromisePromise resolve 的结果应对应着 `roles` 配置对象中的 `key`
```js
import { access } from '@fesjs/fes';
access.setRole(['admin'])
access.setRole('admin')
```
#### access.setAccess

View File

@ -53,6 +53,46 @@ export default {
</script>
```
### @@initialState
`beforeRender`的返回的内容会写入`@@initialState`
```js
export const beforeRender = {
loading: <PageLoading />,
action() {
const { setRole } = access;
return new Promise((resolve) => {
setTimeout(() => {
setRole('admin');
// 初始化应用的全局状态,可以通过 useModel('@@initialState') 获取,具体用法看@/components/UserCenter 文件
resolve({
userName: 'harrywan'
});
}, 1000);
});
}
};
````
然后我们可以在其他组件中使用:
```vue
<template>
<div class="right">{{initialState.userName}}</div>
</template>
<script>
import { useModel } from '@fesjs/fes';
export default {
setup() {
const initialState = useModel('@@initialState');
return {
initialState
};
}
};
</script>
<style scope>
</style>
```
## API

View File

@ -195,7 +195,7 @@ console.log(access.isDataReady())
- PromisePromise resolve 的结果应对应着 `roles` 配置对象中的 `key`
```js
import { access } from '@fesjs/fes';
access.setRole(['admin'])
access.setRole('admin')
```
#### access.setAccess

View File

@ -53,6 +53,46 @@ export default {
</script>
```
### @@initialState
`beforeRender`的返回的内容会写入`@@initialState`
```js
export const beforeRender = {
loading: <PageLoading />,
action() {
const { setRole } = access;
return new Promise((resolve) => {
setTimeout(() => {
setRole('admin');
// 初始化应用的全局状态,可以通过 useModel('@@initialState') 获取,具体用法看@/components/UserCenter 文件
resolve({
userName: 'harrywan'
});
}, 1000);
});
}
};
````
然后我们可以在其他组件中使用:
```vue
<template>
<div class="right">{{initialState.userName}}</div>
</template>
<script>
import { useModel } from '@fesjs/fes';
export default {
setup() {
const initialState = useModel('@@initialState');
return {
initialState
};
}
};
</script>
<style scope>
</style>
```
## API