Walter White Walter White - 5 days ago 5
Javascript Question

set variable from component in instance

I want to set data variable of Vue instance from component. Is that even possible.

Vue.component('graph', {
template: '',
props: {},
data: function () {
methods: {
setBtn: function () {
//here i want to set ShowBtn variable for example to false
},
}, this.getUserRecordStatistic();
});

new Vue({
el: '#app',
data: {
showBtn: null
},
methods: {},
});

Answer

This should do the trick:

Vue.component('graph', {
  template: '',
  props: {},
  data: {},
  methods: {
    setBtn: function () {
      app.showBtn = false;
    },
  },
});

var app = new Vue({
  el: '#app',
  data: {
    showBtn: null
  },
  methods: {},
});
Comments