Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function in Mixins Vuejs not found

Tags:

mixins

vuejs2

Hello I have a component:

<template>
 <upload-btn 
   color="black" 
   title="Carica foto" 
   :fileChangedCallback="fileChange" />
</template>
<script>
import  fileUploadMixin from './../mixins/fileUploadMixin';
export default {
  name: 'compoment',
  mixins: [fileUploadMixin],
  components:{
    'upload-btn': UploadButton
  },
  data(){..},
  methods: {
    fileChange(file){
      this.fileChanged(file);
    }
   }
</script>

And then my Mixin:

export default {
  data () {

  },
  methods: {
    fileChanged(file){
      if(file){
        this.itemImage = file;
        this.previewImage = URL.createObjectURL(file);
      }
    }
  }
}

The problem is it return this error like the mixins not is included, but actually is imported.

vue.runtime.esm.js?2b0e:1878 TypeError: this.fileChanged is not a function

I have tried also change my mixin with:

methods: {
    fileChanged: function(file){}
}

but it doesn't work.

What i'm wrong?

like image 389
LorenzoBerti Avatar asked Mar 04 '23 10:03

LorenzoBerti


1 Answers

For others developers.

I'have solved.

The problem was that my Mixins file extension was wrong.

I have put Mixin.vue instead of Mixin.js, thank you all for answers.

like image 163
LorenzoBerti Avatar answered May 05 '23 14:05

LorenzoBerti