0

Here is an example from the book "The Majesty of Vue", it works fine. But I was trying to make the code shorter and failed.

So in the computed properies there is a function:

search: function(){
    var query = this.query
    return this.stories.filter(function(story){
      return story.plot.includes(query)
    });

I tried to remove var query = this.query and add directly to return story.plot.includes(this.query). But this way it doesn't work. Why? Isn't it the same?

Ren
  • 71
  • 2
  • 12
  • Duplicate TL;DR ~ `return this.stories.filter(story => story.plot.includes(this.query))` – Phil Sep 10 '18 at 03:12

1 Answers1

0

Can you try the following:

  search () {
    return this.stories.filter((story) => {
      return story.plot.includes(this.query)
    });
  }
asanas
  • 3,782
  • 11
  • 43
  • 72