我正在使用vueJS 2.6.10,我的组件发出未定义的值

时间:2019-09-26 13:26:17

标签: javascript typescript vue.js vue-component emit

我正在使用Vue.js 2.0,并且正在尝试从子组件向父组件发出事件。

该事件在父组件上执行得很好,但是传递的值不确定吗?

您可以在下面看到我的代码:

子组件:

<template>
<div class="input-file-container" :class="classDiv">
  <input :id="'upload-file-'+item.id" :name="item.id" type="file" v-on:change="handleImageUpload" />
</div>
</template>
<script lang="ts">
    @Component
    export default class InputFileComponent extends Vue {
        public image:string = '';
        @Prop() public item?: PieceIdentite;

        public handleImageUpload (e:Event) {
            /* ... */
            imageCompression(file, options).then( (compressedFile:Blob) => {
                /* ... */
                myService.myFuction(formData).then( response =>{
                    vm.$emit('input', {
                        'formData': formData,
                        checkFile : response
                    });
                });
            });
        }
    }
</script>

父组件:

    <template>
      <div class="input-file-container" >
            <InputFileComponent :item="item" @input="inputFileValue(input)" ></InputFileComponent>
      </div>
    </template>
<script lang="ts">
    /* ... */
    @Component({
        components: {
            InputFileComponent
        },
    })
    export default class PieceIdentite extends Vue {
        public checkImage:any;
        public inputFileValue(input:any){
            this.checkImage = input ;
            console.log('input::', this.checkImage);
        }
    }
</script>

当调用“ handleImageUpload”事件时,“ inputFileValue”函数可以很好地执行,但是输入值值得未定义 有人可以帮我吗?

0 个答案:

没有答案