Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lmhcoding
committed
Sep 29, 2020
1 parent
6890f7e
commit cc1a3a5
Showing
1 changed file
with
9 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,20 @@ | ||
# ``useTitle`` | ||
--- | ||
|
||
用于设置页面的标签页标题 | ||
Composition Function that sets title of the page | ||
|
||
## API | ||
|
||
```typescript | ||
export declare function useTitle( | ||
title: string, | ||
restoreOnUnMount?: boolean | ||
): (title: string) => void; | ||
``` | ||
|
||
## Params | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| ---------------- | ------------------------ | ------- | ------ | | ||
| title | 标签页标题 | string | | | ||
| restoreOnUnMount | 组件卸载时是否恢复原标题 | boolean | false | | ||
|
||
## Methods | ||
|
||
该 Hook 返回以下函数: | ||
|
||
| 函数签名 | 描述 | | ||
| ------------------------ | ---------------- | | ||
| (title: string) => void | 用于设置页面标题 | | ||
|
||
## Example | ||
|
||
<UseTitle/> | ||
|
||
|
||
## Code | ||
## Usage | ||
--- | ||
|
||
```vue | ||
<template> | ||
<input v-model="title"/> | ||
<button @click="updateTitle">更新标题</button> | ||
</template> | ||
<script> | ||
import { useTitle } from 'composition-fn' | ||
import { ref } from 'vue' | ||
export default { | ||
setup () { | ||
const setTitle = useTitle('title', true) | ||
const title = ref('title') | ||
const updateTitle = () => { | ||
setTitle(title.value) | ||
} | ||
return { | ||
title, | ||
updateTitle | ||
} | ||
import { useTitle } from 'composition-fn' | ||
export default { | ||
setup () { | ||
// 返回值为 setTitle 函数可用来更新 title | ||
useTitle('title') | ||
} | ||
} | ||
} | ||
</script> | ||
<script> | ||
``` | ||
|