How to import mixins into single file Components?

Asked

Viewed 102 times

0

When trying to import mixin the following problem occurs

Error in render: "Typeerror: Cannot read Property 'Components' of Undefined"

But there is nothing abnormal in the Components because when taking mixin everything works normally.

methods/metodo_Div.js

export default {
  methods : {
        inserirDiv (event) {
            let componente = new flexdiv().$mount();
            this.$refs.filhosDoElemento.insertAdjacentElement('beforeend', componente.$el );
        },  
    }
}

./App.

import { methodDiv } from './metodos/metodo_Div'
...
mixins : [methodDiv],
...

Obs. I am using Browserify.

  • In your code I don’t see components nowhere. You can show the line that has that?

  • @Sergio, I’m done, thank you

2 answers

1


I arranged it this way

methods/metodo_Div.js

export const metodoDiv = {
  methods : {
        inserirDiv (event) {
            let componente = new flexdiv().$mount();
            this.$refs.filhosDoElemento.insertAdjacentElement('beforeend', componente.$el );
        },  
    }
}

./App.

import { metodoDiv } from './metodos/metodo_Div'
...
mixins : [metodoDiv],
...

Remembering that the name of the instantiated variable in import must be equal to const defined in mixin.

1

You can simply remove as {}, wouldn’t that be enough? I think the component would work. It would

import metodoDiv from './metodos/metodo_Div'
...
mixins : [metodoDiv],
...
  • guy I tried to take here and it didn’t work, I think it’s some kind of convention because it’s not the import of a component but a simple mixin, the ? } helps organize better too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.