Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The first argument is required and must be an <img> or <canvas> element. #95

Closed
onukselcuk opened this issue Mar 11, 2021 · 7 comments
Closed

Comments

@onukselcuk
Copy link

onukselcuk commented Mar 11, 2021

I'm getting "The first argument is required and must be an <img> or <canvas> element."

@Agontuk
Copy link
Owner

Agontuk commented Mar 11, 2021

Provide a sample how you're using it. You can also check the example project.

@onukselcuk
Copy link
Author

I'm using vue typescript in nuxt.js. cropper ref is not recognized. I couldn't find the proper type for it. I'm not sure if it's the only problem. I'm using the same setup in another project and it works fine. But the version is 4.1.0 in that project. I could try downgrading the package but I don't prefer to do it.

    <input
      ref="fileInput"
      accept=".jpg, .jpeg, .png"
      style="display: none"
      type="file"
      @input="onFileSelect"
    />
    <Dialog
      id="upload-profile-photo-dialog"
      :visible.sync="imageCropperPopupActive"
      :style="{ width: '50vw' }"
      :modal="true"
      class="popup-dialog"
    >
      <template #header>
        <div class="header-top-red-line"></div>
        <h2 class="dialog-header">Upload Profile Photo</h2>
      </template>
      <div>
        <div class="w-full h-full">test</div>
        <vue-cropper
          v-show="imageCropperActive"
          ref="cropper"
          :src="selectedFile"
          alt="Source Image"
        ></vue-cropper>
      </div>
    </Dialog>
    ...
    interface $refs {
       cropper: CropperData
       fileInput: HTMLImageElement
	}
    ...
    data(){
      imageCropperPopupActive: false as boolean,
      imageCropperActive: false as boolean,
      selectedFile: '' as string,       
    }
    ...
    methods:{
      onFileSelect(e) {
        const file = e.target.files[0]
        this.mime_type = file.type
        if (typeof FileReader === 'function') {
          this.imageCropperPopupActive = true
          const reader = new FileReader()
          reader.onload = (event) => {
            // @ts-ignore
            this.selectedFile = event.target.result
            this.$refs.cropper.replace(this.selectedFile)
          }
          reader.readAsDataURL(file)
          this.imageCropperActive = true
          e.target.value = ''
        } else {
          alert('Sorry, FileReader API not supported')
        }
      },    
    } 


    

@onukselcuk
Copy link
Author

I found the problem. I'm using the wrong version. Since nuxt.js is still based on vue2 I should be using 4.2.0 version of this package.

@CavalcanteLeo
Copy link

I'm on version 5, and getting this error

Captura de Tela 2021-06-16 às 03 10 49

@VladimirMarahovskiy
Copy link

необходимо понизить версию плагина

@hassnian
Copy link

hassnian commented Feb 1, 2022

I found the problem. I'm using the wrong version. Since nuxt.js is still based on vue2 I should be using 4.2.0 version of this package.

this worked for me!!

@Edmilson-C
Copy link

I found the problem. I'm using the wrong version. Since nuxt.js is still based on vue2 I should be using 4.2.0 version of this package.

This worked for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants