Reducing the number of hard-coded variables and properties, and reducing redundancy

When looking at the Vue JavaScript, it is quickly evident that it can be optimized by introducing global variables and setting more local variables in the functions to make it more readable. We can also use existing functionality to stop repeating ourselves.

The first optimization is in our filterRow() method where we check whether filter.field is active. This is also repeated in the isActiveFilterSelected method we use to show and hide our radio buttons. Update the if statement to use this method instead, so the code is as follows: 

      ...    if(this.filter.field === 'isActive') {    result = (typeof this.filter.query === 'boolean') ?        (this.filter.query === person.isActive) ...

Get Vue.js 2.x by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.