const app = new Vue({
el: '#app',
data: {
comments: [ ]
},
methods: {
async getComments () {
/* axios.get('http://localhost/comments/getComments.php').then(res => {
this.comments = res.data.result
}) */
// const {data: {code, result}} = await axios.get('http://localhost/comments/getComments.php')
// this.comments = result
try {
const res = await axios.get('http://localhost/comments/getComments.php')
this.comments = res.data.result
} catch (err) {
// 对错误信息进行处理
}
}
},
created () {
/*
尽量不要直接在create中写大量代码,应该现在methods中封装一个函数,再在created中调用
async一定需要重新封装函数
*/
this.getComments()
}
})