Functions don't work getApiToken() and setApiToken(token). What is the reason?

0 like 0 dislike
4 views
Need to write a function getApiToken() which will return a token from the properties api_token. And also the function setApiToken(token) which will be api_token to register a new token after a successful login and also record it in localStorage. What is wrong in my code?
let api_config = { api_url: API_HOST + 'api/', api_token:" } setApiToken function(token) { console.log('token', token) api_config.api_token = token localStorage.setItem('token', token) return localStorage.setItem('token', token) } getApiToken function() { console.log('api_config.api_token', api_config.api_token) return api_config.api_token } export default {api_config, setApiToken, getApiToken}


Then I call the function
headers: { Authorization: 'Bearer' + getApiToken.api_config.api_token }


And setApiToken(response.data.token)
By clicking on the login button.
Using axios, vue.js
by | 4 views

2 Answers

0 like 0 dislike
nastya_zholudeva, apparently you have the import here is
getApiToken import from './file'
In this case, it imports everything from the export default {api_config, setApiToken, getApiToken}
Write
import { getApiToken } from './file'

And remove the default export
export {api_config, setApiToken, getApiToken}
by
0 like 0 dislike

Then I call the function
headers: { Authorization: 'Bearer' + getApiToken.api_config.api_token }



I don't see a call function. Could just be Authorization: 'Bearer' + getApiToken() wanted to write?
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 2, 2019 by CyberJedi
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 22, 2019 by Rebldomakr
110,608 questions
257,186 answers
0 comments
33,672 users