programing

Mixins Vuejs에서 기능을 찾을 수 없습니다.

yoursource 2022. 8. 13. 15:30
반응형

Mixins Vuejs에서 기능을 찾을 수 없습니다.

안녕하세요 컴포넌트가 있습니다.

<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>

그리고 나의 믹스인:

export default {
  data () {

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

문제는 mixin이 포함되어 있지 않지만 실제로 Import된 것처럼 이 오류를 반환한다는 것입니다.

vue.runtime.esm.js?2b0e:1878 TypeError:이것.fileChanged는 함수가 아닙니다.

다음 제품과의 믹스인 변경도 시도했습니다.

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

효과가 없어요.

뭐가 잘못됐지?

다른 개발자용.

나는 해결했다.

문제는 Mixins 파일 확장자가 잘못되었다는 것입니다.

믹스인을 넣었습니다.Mixin.js 대신 vue를 이용해 주셔서 감사합니다.

혼합에서 데이터 블록을 제거하거나 데이터 블록에서 빈 개체를 반환해 보십시오.

믹스인은 다음과 같이 계산해야 합니다.

export default {
    data () {},
    computed: {
         fileChanged(file){
              if(file){
                   this.itemImage = file;
                   this.previewImage  = URL.createObjectURL(file);
              }
          }
      }
 }

언급URL : https://stackoverflow.com/questions/54957760/function-in-mixins-vuejs-not-found

반응형