我的vue组件是这样的:
<template>
<div class="modal" tabindex="-1" role="dialog">
...
<div class="form-group">
<label for="change-image">Change image</label>
<input type="file" name="replace" v-on:change="changeImage">
</div>
<div class="form-group">
<label for="alt-image">Alt attr</label>
<input type="text" class="form-control" v-model="altImage">
</div>
<div class="checkbox">
<label>
<input type="checkbox" v-model="mainCover"> Set Cover
</label>
</div>
<button type="button" class="btn btn-success" @click="editImageProduct">
Edit
</button>
...
</div>
</template>
<script>
export default{
...
data() { return {altImage: '', mainCover: '', imageChanged: '', image: ''}},
methods: {
editImageProduct(event) {
const payload = {alt_image: this.altImage, main_cover: this.mainCover, image_changed: this.imageChanged}
this.$store.dispatch('editImageProduct', payload)
},
changeImage(e) {
var files = e.target.files || e.dataTransfer.files
if (!files.length)
return;
this.createImage(files[0])
this.imageChanged = files[0]
},
createImage(file) {
var image = new Image()
var reader = new FileReader()
var vm = this
reader.onload = (e) => {
vm.image = e.target.result
};
reader.readAsDataURL(file)
},
}
}
</script>
我想将参数发送到控制器。它将通过模块,api,路由和控制器
在控制器上,我喜欢这样:
public function editImage(Request $request)
{
dd($request->all());
}
执行时,结果如下:
数组:5 [
&#34; alt_image&#34; =&GT; &#34;测试alt&#34;
&#34; main_cover&#34; =&GT;真
&#34; image_changed&#34; =&GT; []
param image_changed为空
然而在组件上,我执行console.log,它显示结果
当我执行console.log(files [0])时,结果如下:
我该如何解决这个问题?