InterviewSolution
| 1. |
How would you describe computed properties in Vue.js? |
|
Answer» Vue.js provides an amazing platform for achieving dynamism or static values to be visual on the template. The use of DIRECT hardcoding into the HTML, text outburst or MODEST expressions to transform the data has been a way for achieving the basics. Complex computations have necessitated the development of computed properties. Computed property declaratively describes how one value solely depends on other values. Computed properties have revolutionized complex expressions in that we can create properties which can alter, manipulate, transform and present information in a more readable, efficient and UNDERSTANDABLE manner. Computed properties use methods in its library which is a huge plus. Methods are ALWAYS recomputed when ACCESSED unlike computed property which does not recompute thus providing accurate outputs. Computed properties can be used in so many ways. Data filtering, calculations, execution of Boolean conditions are just a few of the applications of computed properties. Below is a basic example of a computed property that uses count: <div> </template> <script> Export default { name: “HelloWorld”, data() { return{ ShopNumber: 2 } }, Computed: { Count: function() { Return ‘The shop number is ‘ + this.shopNumber } } }; </script> <div>From the above count property, this.shopNumber is the dependency data and it returns a sentence that has this.shopnumber that is displayed in the template. |
|