Created
October 26, 2019 12:29
-
-
Save shershen08/9b419b1205e3bf770a06908fedcebbb3 to your computer and use it in GitHub Desktop.
converting Vue components to Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ListItem } from '@/types/index'; | |
import { Component, Prop, Model, Provide, Watch, Vue } from 'vue-property-decorator'; | |
import LIST from './../../../data/starters'; | |
import SearchItem from './SearchItem.vue'; | |
import SearchForm from './SearchForm.vue'; | |
@Component({ | |
name: 'Search', | |
components: { | |
SearchItem, | |
SearchForm, | |
}, | |
}) | |
export default class Search extends Vue { | |
public list: ListItem[] = LIST; | |
public labels: string[] = []; | |
public results: ListItem[] = []; | |
private components = { | |
SearchItem, | |
SearchForm, | |
}; | |
private mounted() { | |
this.results = this.list; | |
this.list.forEach( (l) => { | |
this.labels = this.labels.concat(l.features); | |
}); | |
this.labels = [...new Set(this.labels)]; | |
} | |
private onSeachTextChanged(val: string) { | |
this.results = this.list.filter((i: ListItem) => { | |
return i.title.toLowerCase().includes(val.toLowerCase()); | |
}); | |
} | |
private onSeachTagChanged(val: string) { | |
this.results = this.list.filter((i: ListItem) => { | |
return i.features.includes(val); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment