Vue: Call methods outside of instance

Created on 26 Aug 2015  ·  1Comment  ·  Source: vuejs/vue

When extended Vue and adding additional methods, howcome it's not possible to call from outside the instance?

// mixin.js
module.exports = {
  created: function () {
    this.hello()
  },
  methods: {
    hello: function () {
      console.log('hello from mixin!')
    }
  }
}

// test.js
var myMixin = require('./mixin')
var Component = Vue.extend({
  mixins: [myMixin]
})
var component = new Component() // -> "hello from mixin!"
// mixin.js
module.exports = {
  methods: {
    hello: function () {
      console.log('hello from mixin!')
    }
  }
}

// test.js
var myMixin = require('./mixin')
var Component = Vue.extend({
  mixins: [myMixin]
})
var component = new Component();
component.hello();

component.hello is not a function

Most helpful comment

Hi, why its closed? do you have solution?

>All comments

Hi, why its closed? do you have solution?

Was this page helpful?
0 / 5 - 0 ratings