R
R
run1822020-04-02 10:51:09
JavaScript
run182, 2020-04-02 10:51:09

How to prevent multiple instances of components from running?

If the method is called a second time, then a copy of the component will be created, how to prevent this?

<div id="app">
   <component v-bind:is="currentComponent"></component>
</div>

new Vue({
  el: "#app",
  name: 'root',
  data: function () {
    return {
      currentComponent: 'game-start-view'
    }
  },
  methods: {
    getLevel() {
      this.currentComponent = "game-level";
    },
    getGame() {
      this.currentComponent = "game-agreement";
    },
    stopGame() {
      this.currentComponent = "game-start-view";
    }
  }
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
i10dev, 2019-09-22
@uzi_no_uzi

$( window ).resize(function().....)
try this

I
Igor Stasyuk, 2020-04-02
@HikariNoSekai

You are some kind of hardcore, but what prevents you from doing this with different components initially and attaching everything to v-if and displaying the one you need, well, or make similar logic with slots

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question