博文背景
{{ message }}
this.axios.get(‘xxx’).then(response=>(this.message=response.data))后面接箭头函数可以返回结果但是直接改成普通函数不可以返回结果
解决办法
<template>
<div id="app">
<pre>{{ info }}</pre>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
info: "waiting for api requesting"
}
},
async mounted() {
await this.axios.get('https://httpbin.org/get').then(function(response) {
console.log(response.data);
console.log(typeof(response.data))
return Promise.resolve(this.info=response.data["url"]);
})
}
}
async mounted() {
let that=this;
await this.axios.get('https://httpbin.org/get').then(function(response) {
console.log(response.data);
console.log(typeof(response.data))
return Promise.resolve(that.info=response.data["url"]);
})
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
font-size: 18px;
color: #2c3e50;
}
</style>
参考链接: https://zh.javascript.info/object-methods
|