> For the complete documentation index, see [llms.txt](https://laterly.gitbook.io/hooks-vue3/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://laterly.gitbook.io/hooks-vue3/usetitle.md).

# useTitle

#### 基础用法

```html

<template>
   <div>Hello World! {{title}}</div>
</template>

<script setup lang="ts">

import { useTitle } from "hooks-vue3";

// 使用默认标题模板，直接将 "Vue App" 设置为页面标题
const title = useTitle("Vue App");

// 使用自定义标题模板，将 "Page Title" 添加到页面标题中
useTitle("Page Title", { template: "My Site | %s", isPrevOnUnmount: true });
</script>

```

### API

```typescript
const title = useTitle();
```

### 参数

```typescript

export type UseTitleOptions = {
  template?: string | ((title: string) => string); //将默认的标题模板 %s 应用于指定的标题字符串
  isPrevOnUnmount?: boolean; //是否在组件卸载重置上一个的标题
};

function useTitle(newTitle?: string, options?: UseTitleOptions): Ref<string>

```

```typescript
```
