[Vuejs]-Vue.js Set value in computed properties

4👍

Attributes defined in data and computed should be mutually exclusive – defining the same attribute in both places is asking for trouble. Also, objects under data should have default values.

So, instead, have your computed return a different object which is all of the transformed values. Leave the settings that your inputs are bound to with v-model alone. Then you can bind separately to the computed object and display it to your user if you like.

data() {
        return {
            settings: {
                "apple": "",
                "banana": "",
                "orange": ""
            }
        }
    },

computed: {
        transformed_settings: function () {
            /* create and return an object with transformed apple, banana, orange */
        }
    },

0👍

The easiest way is to declare apple, banana and Orange as data elements or variables. Define functions based on a user input under methods (Not computed) then use @change=”CheckUserInput” property in the inputboxes

Leave a comment