-1

hello guys are this possible to assign a value to axios success so I can use that variable into other function for eg :-

<script>

var x ="";
export default {
  methods:{
  getshop(){
    this.$http.get('http://localhost:3000/api/shopestablishments') .then(function (response) {        
    return x= response.data;//how i can assign value of x from here
      })
  },

  onClick(){       
    // how I can use assign variables of x over here
             },
    },

}
</script>

i search a lot and got confused how i can do this thing

Rocky
  • 319
  • 3
  • 8
  • 23
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Andreas Mar 28 '18 at 10:11
  • Your code looks weird, since you have 2 `return`s in the same function. – Baumannzone Mar 28 '18 at 10:14

1 Answers1

1

Try this

getshop() {
  this.$http.get('http://localhost:3000/api/shopestablishments') 
    .then(function (response) {
      // Save response.data in variable `x`         
      var x = response.data;
      // Call second function with response.data
      this.yourFunction(x);
    })
}
Baumannzone
  • 760
  • 2
  • 19
  • 38