Comments do not have enough space , so I add this as an answer, but this is just a concept, since I have very low experience with Vue.
From the documents
// Add a request interceptor axios.interceptors.request.use(function (config) { // Do something before request is sent return config; }, function (error) { // Do something with request error return Promise.reject(error); }); // Add a response interceptor axios.interceptors.response.use(function (response) { // Do something with response data return response; }, function (error) { // Do something with response error return Promise.reject(error); });
So, the concept would be something like this:
- Set a custom title from Laravel .
- When creating / starting a Vue application, get your own header and set it somewhere global.
When executing the request, intercept it and add the CSRF token from global storage
axios.interceptors.request.use (function (config) {// Get your token from where you saved it and add it to the request});
Intercept the answer and save the new token
axios.interceptors.response.use (function (response) {// Store the new CSRF token in the same place where you saved the first.});
Loop forever
source share