{{ state.text }}
``` -------------------------------- ### Options API v-model 绑定使用 useVModels Source: https://vueuse.nodejs.cn/core/useVModels 在 Options API 中使用 useVModels 来处理 props 的 v-model 绑定。在 setup 函数中调用 useVModels,并将返回的对象解构出来。你可以直接访问和修改这些响应式属性,它们会自动触发相应的 emit 事件。 ```typescript import { useVModels } from '@vueuse/core' export default { props: { foo: String, bar: Number, }, setup(props, { emit }) { const { foo, bar } = useVModels( props, emit ) console.log(foo.value) // props.foo foo.value = 'foo' // emit('update:foo', 'foo') }, } ``` -------------------------------- ### useActiveElement 组合式函数基础用法 - Vue 3 Source: https://vueuse.nodejs.cn/core/useActiveElement 在 Vue 3 Script Setup 中导入并使用 useActiveElement 函数。该函数返回一个反应式引用,包含当前获得焦点的 DOM 元素。通过 watch 监听其变化以捕获焦点事件。 ```typescript ``` -------------------------------- ### useOffsetPagination Composable Setup with JavaScript Source: https://vueuse.nodejs.cn/core/useOffsetPagination Import and configure the useOffsetPagination composable from @vueuse/core using JavaScript. Defines a fetchData callback for handling pagination changes and destructures the returned pagination state object. ```javascript import { useOffsetPagination } from '@vueuse/core' function fetchData({ currentPage, currentPageSize }) { fetch(currentPage, currentPageSize).then((responseData) => { data.value = responseData }) } const { currentPage, currentPageSize, pageCount, isFirstPage, isLastPage, prev, next, } = useOffsetPagination({ total: database.value.length, page: 1, pageSize: 10, onPageChange: fetchData, onPageSizeChange: fetchData, }) ``` -------------------------------- ### Vue.js useAuth with Firebase Authentication Example Source: https://vueuse.nodejs.cn/firebase/useAuth This example demonstrates how to use the `useAuth` composable from VueUse to integrate reactive Firebase authentication into a Vue.js application. It shows the setup for initializing Firebase, obtaining authentication instance, and using `useAuth` to get reactive `isAuthenticated` and `user` states. It also includes a function to handle Google Sign-In using `signInWithPopup` and displays conditional UI based on the authentication status. ```vue{{ user }}
Hello world