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) {
? ? ? ? ? ? // 對(duì)錯(cuò)誤信息進(jìn)行處理
? ? ? ? ? }
? ? ? ? }
? ? ? },
? ? ? created () {
? ? ? ? /*
? ? ? ? ? 盡量不要直接在create中寫大量代碼烙无,應(yīng)該現(xiàn)在methods中封裝一個(gè)函數(shù),再在created中調(diào)用
? ? ? ? ? async一定需要重新封裝函數(shù)
? ? ? ? */
? ? ? ? this.getComments()
? ? ? }
? ? })