[Vuejs]-Computed property other file

0👍

You would need the variable to be converted by Vue into a reactive variable. You can do that by using the object as the data initializer of your Vue instance.

const vars = {
  variab: 0
};

new Vue({
  el: '#app',
  data() {
    return {
      vars
    };
  },
  computed: {
    booleano() {
      if (this.vars.variab == 0) {
        return true;
      }
      return false;
    }
  }
});

setTimeout(() => {
  vars.variab = 1;
}, 1000);
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.min.js"></script>
<div id="app">
  <div v-if="booleano">Yes</div>
  <div v-else>No</div>
</div>

Leave a comment