-1

I sit all day and don’t understand why it doesn't work. I have X-CSRF-TOKEN in the header. How do I get it? I tried it in different ways and no one method works.

Below is my Vue.js

    <script>

    import axios from "axios";

    export default {

      name: "UploadFiles",

      data() {
        return{
          file: ""
        }
      },

      methods:{

        selectFile(){
          this.file = this.$refs.file.files[0]
        },

        async sendFile() {


          const formData = new FormData();
          formData.append('file', this.file);

          await axios.post('/user/uploadImages', formData)


        }


      }


    }


    </script>

1 Answers1

0

Try like this

let token = document.head.querySelector('meta[name="csrf-token"]');

axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

if (token) {
    axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
}
F.E
  • 688
  • 6
  • 10