Skip to content

Commit

Permalink
docs: show dayjs() composable examples
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianWowra committed Oct 12, 2024
1 parent c28e874 commit b5d3a77
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ You can use the provided `$dayjs` to access Day.js in template.

## Composables

You can use the useDayjs composable to access Day.js anywhere.
You can use the `useDayjs()` and `dayjs()` composables to access Day.js anywhere.

```js
```vue
<script setup>
import { useDayjs } from '#dayjs' // not need if you are using auto import
const dayjs = useDayjs()
dayjs.locale('fr')
dayjs.extend(...)
import { useDayjs, dayjs } from '#dayjs' // not need if you are using auto import
// access for dayjs globals
useDayjs().locale('fr')
useDayjs().extend(...)
// access for dayjs instance
console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'))
</script>
```

Expand Down
8 changes: 5 additions & 3 deletions playground/app.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<script lang="ts" setup>
import { useDayjs } from '#dayjs'
import { dayjs, useDayjs } from '#dayjs'
const dayjs = useDayjs()
const card = false
const icon = false
// access for dayjs instance
console.log(dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'))
console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'))
// access for dayjs globals
console.log(useDayjs().isDayjs(new Date()))
</script>

<template>
Expand Down

0 comments on commit b5d3a77

Please sign in to comment.