Handling unexpected side effect in computed properties - VueJS

前端 未结 4 434
闹比i
闹比i 2021-01-07 23:12

In the following code, I\'m trying to use the getTranslation object to map values present in originalKeys array and push the values in a new array

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 23:51

    As other answers mentioned this is because you are mutating the original data in a computed property. You should use a method to do this part of the job.

    methods:{
        changes(tableHeaders){
            this.selected = tableHeaders[0];
            this.allKeys = tableHeaders;
        }
    },
    computed:{
        getkeys(){
            // Your code...
            this.changes(tableHeaders);
        }
    },
    data: function(){
        return{
            // Your data...
        }
    }
    

提交回复
热议问题