Vue.js Custom Filters Two-way Filters


Example

With a two-way filter, we are able to assign a read and write operation for a single filter that changes the value of the same data between the view and model.

//JS
Vue.filter('uppercase', {
    //read : model -> view
    read: function(value) {
        return value.toUpperCase();
    },

    //write : view -> model
    write: function(value) {
        return value.toLowerCase();
    }
});

/*
 * Base value of data: 'example string'
 *
 * In the view : 'EXAMPLE STRING'
 * In the model : 'example string'
 */