T
T
Timofey Mikhailov2020-04-26 11:35:33
Vue.js
Timofey Mikhailov, 2020-04-26 11:35:33

How do I use data in App.vue?

Hello everybody.
The question is probably quite simple, but I do not understand what the problem is ...
Here is the code: (this is the App.vue file )

<template>
  <div id="app">
    <router-view/>
    <VuePopup
      v-if="this.showPopup"
      @closePopup="closePopup()"
    />
  </div>
</template>

<script>
import VuePopup from './components/VuePopup'

export default {
  name: 'App',
  date(){
    return {
      showPopup: true,
    }
  },
  components: {
    VuePopup
  },
  methods: {
    closePopup(){
      this.showPopup = false
    }
  },
  created() {
    this.$store.commit('runServer')
  }
}
</script>


So, because I chose to use Vue-Router , my App.vue can launch several different pages, which must contain a VuePopup component .
I thought, why import it every time in every component, and decided to shove it into the root.
Everything works fine, but the trouble came from where I didn’t expect ...
I just can’t use data . What could be the problem?

The console gives an error:
Property or method "showPopup" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-04-26
@JimmiJanger

5ea54854100e6767673955.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question