你好伙计们这可以为axios成功分配一个值,所以我可以将该变量用于其他函数,例如: -
<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>
我搜索了很多并且对我如何做这件事感到困惑
答案 0 :(得分:0)
试试这个
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);
})
}