鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ 導(dǎo)出的vue組件,如何在ajax中給data賦值

導(dǎo)出的vue組件,如何在ajax中給data賦值

通過get請求到的TotalComment,如何賦值給data里的totalComment

export default {

    data() {

        return {
            contentId:1,
            focusflag:true,
            totalComment:TotalComment,
            reply:'',
            name:'金醫(yī)生',
            articleContent:'',
            active:'',
            commentList:commentList,
            goodCommentList:goodCommentList,
            totalComment:TotalComment,
        }
    },
    
    methods: {
    //獲取全部評論
        getAllComment:function () {
            Axios({
                // `url` 是用于請求的服務(wù)器 URL
                url:devhttpUrl + '/content/comments/all?contentId='+1+'&pageNo=1&pageSize=20&totalItems=-1',
                // `method` 是創(chuàng)建請求時使用的方法
                method: 'get', // 默認(rèn)是 get
                headers: {'Authorization':'Bearer '+ token },
                // data:postData
            }).then(function (result) {
                if(result.data.errCode==0){
                    var dataobj=result.data.data.items;
                    TotalComment=result.data.data.totalItems;
                    console.log(TotalComment)
                    for(var i=0;i<dataobj.length;i++){
                        commentList.push({id:dataobj[i].id,name:dataobj[i].userNickName,time:dataobj[i].creationTime,replyNo:dataobj[i].replyCount,cool:dataobj[i].likeCount,content:dataobj[i].content})
                    }
                }
                else{
                    Toast(result.data.errMsg);
                }
                console.log(TotalComment)
                //that.$set(that,'totalComment',TotalComment);
            }).catch(function (error) {
                console.log(error)
            })

}

回答
編輯回答
心癌

then(res => { this.xxx = xxxx })

2017年10月18日 03:49