# useDocumentVisibility

#### 基础用法

```html
<template>
  <div>Hello World!</div>
</template>

<script setup lang="ts">
import { watchEffect } from "vue";
import { useDocumentVisibility } from "hooks-vue3";
const visibility = useDocumentVisibility();
watchEffect(() => {
  // 根据可见性状态执行不同的操作
  if (visibility.value === "hidden") {
    // 页面不可见
    console.log("页面不可见");
  } else {
    // 页面可见
    console.log("页面可见");
  }
});
</script>
```

### API

```typescript
const visibility = useDocumentVisibility();
```

### 参数

```typescript
type VisibilityState = 'visible' | 'hidden' | 'prerender' | undefined;

function useDocumentVisibility(): Ref<VisibilityState>

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://laterly.gitbook.io/hooks-vue3/usedocumentvisibility.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
