I am trying to declare getTemp variable global so that i can use it in other function. VUE.JS

dannnnnnn

I am trying to declare getTemp variable global so that i can use it in other function. VUE.JS

var weather = new Vue({
    el: '#weather',

    data: {
        getTemp: []
    },

    created: function () {
        this.fetchData();
    },        

    methods: {
        fetchData: function () {
            this.$http.get('https://vt')
                      .then(response => {
                         this.getTemp = response.data;

                      })
        }
    },
})
;
Egor Stambakio

Root instance data properties are accessible throughout the app with this.$root.variableName:

new Vue({
  el: '#app',
  data: {
    getTemp: 'Hello World!'
  },
  components: {
    'child1': {
      template: `<div><p>child1, getTemp: {{ $root.getTemp }}</p>
      	<subchild></subchild>
      </div>`,
      components: {
        'subchild': {
          template: `<span>Subchild test: {{ $root.getTemp }}</span>`
        }
      }
    },
    'child2': {
      template: `<p>child2, getTemp: {{ $root.getTemp }}</p>`
    }
  }
});
<script src="https://unpkg.com/vue/dist/vue.js"></script>

<div id="app">
  <child1></child1>
  <child2></child2>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I use LOCAL VARIABLE in function, like a GLOBAL VARIABLE variable for other function

how can I declare a global variable in typescript

In DB2, how can I declare a variable to use in multiple declared global temporary tables within the function..?

How can I make this javascript function not use a global variable?

Can I use a function parameter to create a global variable?

Why am I unable to declare a variable inside a function with a nested function?

i am importing a async function and trying to use it

Is there a way that I can declare the variable outside function?

How can I declare a struct of maps as a global variable?

How can I declare a global variable in Angular 2 / Typescript?

How can I declare a global variable in Ruby on Rails?

why can't I declare a global variable inside an "exec" string

I am trying to give path to the variable so that I can scrape the information contained in that path. But, I m getting empty list

How can i use global functions in Vue?

Declare a textbox as a global variable so it can be reused

Can I use an SQL DECLARE section at global scope in Pro*C?

how can i unset a global variable in function

How can i use a global variable in ruby?

how can I use a global variable in the def?

How can I use this variable on Vue.js?

how can i use variable declared inline in vue js?

I am trying to make a GUI for a app I am working on but when I try print a global variable I get an error. Why?

Can I use a variable template to declare another variable template?

I am trying to install vue3 js

I'm trying to centralize my js scripts so that I can re-use on multiple pages

In Python, can I call the variable from main function - use global variable?

I am trying to pass a variable into a cronSchedule expression function in java

How do I pass a blade variable to a vue instance so I can use it in my JavaScript file?

i am trying to make a new component inside a js variable