[Vuejs]-Global definition does not work in vue.js

0πŸ‘

βœ…

If you are trying to use the named reference of VueJwtDecode, you need to reimport the library in your Signup.vue compoenent since Signup.vue doesn’t understand what VueJwtDecode means.

import VueJwtDecode from 'vue-jwt-decode'
const payload = VueJwtDecode.decode(res.jwt);

However, since you have globally installed the library, it has been installed to the Vue instance, meaning that it is available from the this context within your component. As a result, you can also access it from the component context without reimporting:

const payload = this.$jwtDec(res.jwt);
πŸ‘€David L

0πŸ‘

As document, in your component, you need to use

this.$jwtDec(res.jwt)

instead of

VueJwtDecode.decode(res.jwt);
πŸ‘€ittus

Leave a comment