vue@clickの場合、1回目のクリックは無効で、2回目に効果があります

1262 ワード


export default {
    name: "typhoon",
    data: function () {
        return {  
            typhoonYear: '', //    o
            typhoonYearList: [],//                   
        }
    },
/*               */
getselectYearByDistinct:function() {
    //  
    // var _this = this;
    var option=this.typhoonYearList;
    this.$axios.get(request.selectYearByDistinct)
        .then(function (response) {
            var data=response.data;
            var item =1;
            for (item  in data) {
                if(!option.includes( data[item])) {
                    option.push( data[item]);
                }else {
                    return data[item];
                }
            } 
        })
        .catch(function (error) {
            window.console.log(error);
        });
},

問題:結果は1回目のクリックが無効で、2回目に効果が現れます.


解決策:

mounted() {
    this.getselectYearByDistinct();// mounted()       ,    
},