Filters and functions in vue

In

vue, the filter can only be used after double curly braces or v-blind to achieve the same effect, and the code of the function is not much different. Why use a filter?

Jul.02,2021

  1. All the methods on the Array prototype chain can be solved with the for loop, so why do you add so many methods to it?
  2. what should I do if I don't have filter to use a function?
    2.1 may change the original data, and if I can't change the original data, for example, if my metadata is Date , I only show the date, but I have to calculate the date no more than how many days.
    2.2 copy a new data or calculation attribute without changing the original data? But what if I'm an array? What if my original data changes?
  3. of course, all the above hypothetical methods can be solved, but a small difference in the amount of code is unrealistic, and it may lead to a lot of performance problems, such as more object proxies, dependency collection, and so on.
  4. semantics, the code is for people to see after all.

filters can write multiple filters through pipe characters

{{message | filter1 | filter2}}

while the function implements the same function, it is not so elegant to write


because angular has filters


because angular has filters, it's funny manually.

Menu