Skip to content

useJwt

jwt-decode 的封装。

¥Wrapper for jwt-decode.

示例

Header

{
  "alg": "HS256",
  "typ": "JWT"
}

Payload

{
  "sub": "1234567890",
  "iat": 1516239022
}
Available in the @vueuse/integrations add-on.

安装

¥Install

bash
npm install jwt-decode@^4

用法

¥Usage

typescript
import { useJwt } from '@vueuse/integrations/useJwt'
import { defineComponent } from 'vue'

export default defineComponent({
  setup() {
    const encodedJwt = ref('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyfQ.L8i6g3PfcHlioHCCPURC9pmXT7gdJpx3kOoyAfNUwCc')
    const { header, payload } = useJwt(encodedJwt)

    return { header, payload }
  },
})