Skip to content

Instantly share code, notes, and snippets.

@shershen08
Created October 26, 2019 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shershen08/9b419b1205e3bf770a06908fedcebbb3 to your computer and use it in GitHub Desktop.
Save shershen08/9b419b1205e3bf770a06908fedcebbb3 to your computer and use it in GitHub Desktop.
converting Vue components to Typescript
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