亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Vue.js 在 Laravel 中上傳多張圖片

使用 Vue.js 在 Laravel 中上傳多張圖片

蝴蝶刀刀 2023-06-09 15:26:33
我正在嘗試在 Laravel 中使用 vue.js 上傳圖片,因為我正在使用此鏈接https://jsfiddle.net/b412ruzo/使用 vue.js 上傳圖片,當我提交表單時,我在文件數組中得到以下圖片現在的問題是我無法在 Laravel 控制器中獲取此文件數組當我打印$request->file('files')在我的控制器中,我變得空了。當我打印 $request->input('files') 這就是結果,一個空數組非常感謝有關此問題的任何幫助。代碼片段:data() {     return {    rawData: [],    formData: new Form({        files:[],})..  const header = {             Authorization: "Bearer " + this.token,            };  this.formData        .post(APP_URL + `/api/post`, { headers: header })        .then((response) => {   }
查看完整描述

1 回答

?
四季花海

TA貢獻1811條經驗 獲得超5個贊

不確定您可以通過以下方式發送ajax請求 this.formData.post


嘗試這個


new Vue({

  el: "#app",

  data() {

    return {

      option: {

        maxFileCount: 3

      },

      files:[],

      rawData: [],

    }

  },

  methods: {

    loaddropfile: function(e) {

        e.preventDefault()

      e.stopPropagation()

        alert('ok')

        console.log(e)

    },

    openinput: function() {

        document.getElementById("vue-file-upload-input").click();

    },

    addImage: function(e) {

        const tmpFiles = e.target.files

      if (tmpFiles.length === 0) {

        return false;

      }

      const file = tmpFiles[0]

      this.files.push(file)

      const self = this

        const reader = new FileReader()

      reader.onload = function(e) {

        self.rawData.push(e.target.result)

      }

      reader.readAsDataURL(file)

    },

    removeFile: function(index) {

        this.files.splice(index, 1)

      this.rawData.splice(index, 1)

      document.getElementById("vue-file-upload-input").value = null

    },

    upload: function() {

        alert('Check console to see uploads')

        console.log(this.files)

      axios.post(`${APP_URL}/api/post`,{files:this.files},{ headers: header })

        .then((response) => {});


    }

  },

  mounted(){


  }

})

它會將您的表單數據發送到files密鑰,以便您可以通過以下方式獲取所有文件$request->file('files') 


查看完整回答
反對 回復 2023-06-09
  • 1 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號