Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

<el-form-item :label="$t('modal.driver.upload.file')" required prop="name"> <el-upload…

  1. User

    при нажатии на enter нужно вызвать функцию submitUpload

  2. Assistant

    To handle the Enter key press to trigger the submitUpload function when the user interacts with the upload component in your template, you can add a keydown event listener. Here’s how you could do it:

    1. Add a @keydown.enter event to your el-upload component.
    2. Define the submitUpload method in the script section.

    Here’s an updated version of your code with the required changes:

    <template>
      <el-form-item :label="$t('modal.driver.upload.file')" required prop="name">
        <el-upload
          class="upload-demo"
          ref="upload"
          name="updrvpkg"
          drag
          :with-credentials="true"
          action="/api/v1/admin/driver/upload"
          :auto-upload="false"
          :file-list="fileList"
          :on-change="onChange"
          :on-error="onError"
          multiple
          @keydown.enter="submitUpload">
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">{{ $t('modal.driver.upload.desc') }}</div>
        </el-upload>
      </el-form-item>
    </template>
    
    <script>
    export default {
      data() {
        return {
          fileList: []
        };
      },
      methods: {
        onChange(file, fileList) {
          this.fileList = fileList;
        },
        onError(err, file, fileList) {
          console.error('Error uploading file:', err);
        },
        submitUpload() {
          this.$refs.upload.submit();
        }
      }
    };
    </script>
    

    In this code:

    1. The @keydown.enter="submitUpload" directive on the el-upload component listens for the Enter key press.
    2. The submitUpload method calls the submit method on the el-upload component using a reference (this.$refs.upload.submit()).

    With these changes, pressing Enter while focusing on the upload component will trigger the submitUpload function.