Access the previous value of computed VueJS Access the previous value of computed VueJS vue.js vue.js

Access the previous value of computed VueJS


If you're trying to watch for changes, using watch may be the way to go. It handles prev and next values, and you can assign it to watch your computed...

new Vue({    //...    data() {        return {            selectedLenses: 0        };    },    computed: {        changeSelectedLenses() {            return this.selectedLenses + 2;        }    },    watch: {        changeSelectedLenses(newValue, oldValue) {            alert(`changeSelectedLenses computed property changed from ${oldValue} to ${newValue}`);        }    }});