I won't say much nonsense, let's just read the code~
const httpServer = (opts, data) => { const token = ('token') const PUBLIC = `?token=${token}` let httpDefaultOpts = '' var host = `${}` var prot = `${}` var base = host +(prot?":"+prot:"") if ( === 'post') { httpDefaultOpts = { method: , url: `${base}${}${PUBLIC}`, headers:{ 'Content-Type':'application/text/html;charset=utf-8' //Just change here }, data: data } } else { httpDefaultOpts = opts } return new Promise(function (resolve, reject) { Axios(httpDefaultOpts).then( (res) => { successState(res) resolve(res) } ).catch( (err) => { errorState(err) reject(err) } ) }) }
Supplementary knowledge:Vue gets and stores the AuthorizationToken information returned by the server and adds tokens to each request.
Since the background uses jwt's token for identity permission verification, the background adds the token in the response header after logging in, so the front desk needs to store this token and add a token to the request header for each request so that the server can obtain the token for identity authentication.
Use vue project in the front desk:
(Login component)
{ submitForm(formName) { this.$axios .post('/api/admin/login', { userName: , password: }) .then(successResponse => { = () = () if ( === 200) { =''; ('userName',); //Get and store the AuthorizationToken information returned by the server var authorization=['authorization']; ('authorization',authorization); //Login successfully jump to the page this.$('/dashboard'); } }) .catch(failResponse => {}) } }
(Global configuration js):
//Automatically add request headers to all requests of the same vue project(function (config) { let token = ('authorization'); if (token) { ['Authorization'] = token; } return config; })
Here we also need to consider the issue of token expiration and invalidation, and the blogger will write another blog to supplement it in the future.
The above article on the axios request header change of Content-Type operation in the VUE project is all the content I share with you. I hope you can give you a reference and I hope you can support me more.