How to import mixins into single file components?

0

When trying to import the mixin the following problem occurs

  

Error in render: "TypeError: Can not read property 'components' of undefined"

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

Methods / Method_Div.js

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

./ App.vue

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

obs. I'm using browserify.

    
asked by anonymous 29.11.2017 / 01:20

2 answers

1

I arranged it as follows

Methods / Method_Div.js

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

./ App.vue

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

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

    
29.11.2017 / 12:21
1

You can simply remove the as {}, would not it be enough? I think the component would work. It would be

import metodoDiv from './metodos/metodo_Div'
...
mixins : [metodoDiv],
...
    
30.11.2017 / 01:07