【问题标题】:How to get title in Vue.js如何在 Vue.js 中获取标题
【发布时间】:2021-09-04 15:47:20
【问题描述】:

我整天坐着,不明白为什么它不起作用。 我在标题中有 X-CSRF-TOKEN。 我如何得到它?我尝试了不同的方法,没有一种方法有效。

下面是我的 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>

【问题讨论】:

标签: vue.js axios


【解决方案1】:

这样试试

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;
}

【讨论】:

    猜你喜欢
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2019-09-14
    • 2019-06-13
    • 2017-07-16
    • 2017-07-09
    • 2018-09-15
    相关资源
    最近更新 更多