Skip to content
Advertisement

Vue – Advanced Cropper (Uncaught TypeError: this.$refs.cropper.getResult is not a function)

I have a crop function for Vue Advanced Cropper like this:

JavaScript

My HTML:

JavaScript

I have included the import for Cropper:

JavaScript

Version from package.json:

JavaScript

Everything works until I get to the crop function where it says the following:
Uncaught TypeError: this.$refs.cropper.getResult is not a function

My first thought was, that it may have something to due with looping through multiple images, however it does not work with juse one either. I have tried combining the part from disc and upload to server from here: https://norserium.github.io/vue-advanced-cropper/guides/recipes.html#upload-image-to-a-server

— Edit —

I have export default also, and cropping works, just not getting the results:

JavaScript

Advertisement

Answer

Considering that you are using the same ref name for each element in your v-for it might be possible that this.$refs.cropper is an array. This depends on your version of Vue as well. If that’s the case you might have to pass a parameter to your crop function so that the index of the invoking element is known and getResult can be called correctly.

Try console logging this.$refs. Also maybe see if this thread is useful? Vue.js ref inside the v-for loop

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement