[Vuejs]-Inertia global headers

0👍

Hope this one help you

import axios from 'axios';
import { InertiaApp } from '@inertiajs/inertia-vue3';

axios.interceptors.request.use((config) => {
  const lang = localStorage.getItem('vue_i18n_locale');
  if (lang) {
    config.headers['Accept-Content-Language'] = lang;
    config.headers['Accept-Language'] = lang;
  }
  return config;
});

const app = document.getElementById('app');

new InertiaApp({
  resolve: (name) => import(`./Pages/${name}.vue`),
  setup({ el, App, props, plugin }) {
    return createApp({ render: () => h(App, props) })
      .use(plugin)
      .mount(el);
  },
  page: JSON.parse(app.dataset.page),
});

Leave a comment