VUE gets the data returned by another method

   getNewsData: function () {
        let self=this;
        $.ajax({
            url:"news/ListAll",
            type:"post",
            dataType:"json",
            success:function (result) {
                if(result.code === 200){
                    self.total = result.total;
                    self.newsData = result.data;
                }
            }
        });
    },
    loadCurrentData: function(){

    },
    

how does loadCurrentData get the data of newsData returned by getNewsData?

Jul.14,2021

ajax requests are asynchronous. When did you call both methods


use promise


to define a data in data and copy it to this


default loading, returns promise,?


to ensure that getNewsData has been executed and result.data, has been returned successfully, using this.newsData will not be an empty array when using loadCurrentData.


you judge whether the newDatas is empty and give different data according to the demand


you can use promise to solve

.
Menu