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

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4360f-44a42.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4360f-44a42.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?