在页面创建期间,调用getUserList()函数,
created() {
this.getUserList()
},
发起一次AJAX数据请求,接下来get函数会返回一个promise对象,
methods: {
getUserList(){
// 发起get请求
this.$http.get('users',{parama:queryInfo})
}
},
为了简化promise操作,使用async和await来优化异步操作,
async getUserList(){
// 发起get请求
await this.$http.get('users',{parama:queryInfo})
}
用到await会得到一个数据对象,从这个data对象中解构赋值得到一个data属性并重命名为res
const {data:res}=await this.$http.get('users',{parama:queryInfo})