English
Client API
Client API can be imported from vuepress/client.
Composition API
useClientData
Details:
Returns all the client data ref objects.
Each property can also be accessed by the following composition APIs, except
pageHeadTitle, which can only be accessed viauseClientData().The client data object also provides the following aliases:
frontmatter(pageFrontmatter),head(pageHead),headTitle(pageHeadTitle),lang(pageLang),page(pageData),site(siteData) andsiteLocale(siteLocaleData).The composition APIs also have the following aliases:
useData(useClientData),useFrontmatter(usePageFrontmatter),useHead(usePageHead),useLang(usePageLang),usePage(usePageData),useSite(useSiteData) anduseSiteLocale(useSiteLocaleData).Example:
<script setup lang="ts">
import { useClientData } from 'vuepress/client'
const {
pageData,
pageFrontmatter,
pageHead,
pageHeadTitle,
pageLang,
routeLocale,
siteData,
siteLocaleData,
} = useClientData()
</script>useLayouts
Details:
Returns the layouts ref object.
The value is the layouts registered by all client config files, including the
LayoutandNotFoundlayouts that are required by a theme.Also see:
usePageComponent
Details:
Returns the page component ref object of current page.
The value is the component loaded from the page chunk.
usePageData
Details:
Returns the page data ref object of current page.
Also see:
usePageFrontmatter
Details:
Returns the frontmatter ref object of current page.
The value is the
frontmatterproperty of the page data.
usePageHead
Details:
Returns the head config ref object of current page.
The value is obtained by merging and deduplicating head frontmatter and head config.
useClientData().pageHeadTitle
Type:
ComputedRef<string>Details:
Returns the head title ref object of current page.
The value is obtained by joining the page title and site title. It is a computed ref returned by
useClientDatainstead of being a standalone composition API, and the<title>element is kept in sync with it byuseUpdateHead.The value can be customized via
resolvers.Example:
import { useClientData } from 'vuepress/client'
const { pageHeadTitle } = useClientData()usePageLang
Details:
Returns the language ref object of current page.
The value is the
langproperty of the page data.
usePageLayout
Details:
Returns the layout component ref object of current page.
The value is resolved from the layout frontmatter and the layouts registered by client config files.
Also see:
useRoutes
Details:
Returns the routes ref object.
The value is the
routesproperty of the site data.Also see:
useRouteLocale
Details:
Returns the locale path ref object of current route.
The value is one of the keys of the locales config.
useRoutePath
Details:
Returns the route path ref object of current route.
The value is the
pathproperty of the current route.
useRedirects
Details:
Returns the redirects ref object.
The keys are the source route paths and the values are the target route paths. It is used internally to resolve route paths, see
resolveRoutePath.
useSiteData
Details:
Returns the site data ref object.
useSiteLocaleData
Details:
Returns the site data ref object of current locale.
The properties of current locale have been merged into the root-level properties.
onContentUpdated
Details:
When the content of the markdown file changes, the callback is triggered.
This function can only be called during the
setupphase of the component.<script setup> import { onContentUpdated } from 'vuepress/client' onContentUpdated((reason) => { console.log(`content updated reason: ${reason}`) }) </script>
useUpdateHead
Details:
Returns a function to update the
<head>of current page.It applies the current
usePageHeadvalue to the document head immediately. VuePress keeps the head in sync automatically after the client app is mounted, so this function is only needed when you want to force a synchronous update.This function can only be called during the
setupphase of a component in the client app.
Helpers
defineClientConfig
Details:
Helper for creating clientConfigFile.
Also see:
resolveRoute
Details:
Parses the route of the given link.
Also see:
resolveRoutePath
Details:
Parses the route path of the given link.
Also see:
resolveRouteFullPath
Details:
Parses the route full path of the given link, i.e. the resolved route path with the hash and query of the given link preserved.
Also see:
withBase
Details:
Prefix URL with site base.
Also see:
Constants
There are some constants that available in the client side code.
To shim the types of these constants in client side code, add vuepress/client-types to your tsconfig.json:
{
"compilerOptions": {
"types": ["vuepress/client-types"]
}
}__VUEPRESS_VERSION__
Type:
stringDetails:
Version of VuePress core package.
__VUEPRESS_BASE__
Type:
stringDetails:
The base option from config.
__VUEPRESS_DEV__
Type:
booleanDetails:
An environment flag indicating whether it is currently running in
devmode.
__VUEPRESS_SSR__
Type:
booleanDetails:
An environment flag indicating whether it is currently running in server-side-rendering (SSR) build.
Advanced
resolvers experimental
Type:
Record<string, Function>Details:
An reactive object, methods of which determining how to resolve global computed.
Example:
Customizing the format of <title> in client config file:
import { defineClientConfig, resolvers } from 'vuepress/client'
export default defineClientConfig({
enhance({ app, router, siteData }) {
resolvers.resolvePageHeadTitle = (page, siteLocale) =>
`${siteLocale.title} > ${page.title}`
},
})Caution
resolvers will affect the basic functionality of VuePress. Please make sure you have fully understood its purpose before modifying it.
