0

My vue component like this :

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

I want to send the parameters to controller. It will go through modules, api, routes and controller

On the controller, I do like this :

public function editImage(Request $request)
{
    dd($request->all());
}

When executed, the result like this :

array:5 [

"alt_image" => "test alt"

"main_cover" => true

"image_changed" => []

]

The param image_changed is empty

Whereas on the component, I do console.log, it display the result

When I do console.log(files[0]), the result like this :

enter image description here

How can I solve this problem?

9
  • Possible to reproduce it in a fiddle, I have similar code in my project, which works as expected. Commented May 25, 2017 at 7:44
  • @Saurabh , What do you mean? It looks like my case is different. Try you read my question carefully. I have a problem, when sending it to the controller Commented May 25, 2017 at 7:56
  • Yes, I agree, it is just similar, not same.Possible to reproduce it in a fiddle? Commented May 25, 2017 at 7:59
  • @Saurabh, My code is too much. I may not show all. I just show the code that I think is important. And it seems the code in my question is very obviously a problem. Although I do not show all my code Commented May 25, 2017 at 8:23
  • "When executed, the result like this :" where is this happening in the code ? Commented May 25, 2017 at 9:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.