Skip to content

Instantly share code, notes, and snippets.

@connor11528
Created August 1, 2018 23:44
Show Gist options
  • Save connor11528/ae2f5641cafecfcd49b18c4099836ad5 to your computer and use it in GitHub Desktop.
Save connor11528/ae2f5641cafecfcd49b18c4099836ad5 to your computer and use it in GitHub Desktop.
render and search a list with Vue.js
<template>
<section>
<input type="text" class="form-control" placeholder="Search by job title" v-model="searchTerm">
<div class="list-group mt-2" :style="{ height: this.search_window_height + 'px' }">
<div class="list-group-item list-group-item-action flex-column align-items-start" v-for="jobListing in filteredJobListings">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">
{{ jobListing.title }}
<small>
(<a :href="'https://boards.greenhouse.io/' + jobListing.url" target="_blank"><i class="fas fa-external-link-alt"></i></a>)
</small>
</h5>
<small>{{ jobListing.city }}</small>
</div>
<p class="mb-1">
<a :href="'/companies/' + jobListing.company.slug" target="_blank">{{ jobListing.company.name }} 🔗</a>
</p>
<small>{{ jobListing.company.description }}</small>
</div>
</div>
</section>
</template>
<script>
export default {
props: {
'job_listings_raw': {
required: true,
default(){
return [];
}
}
},
mounted(){
this.$nextTick(()=>{
this.search_window_height = document.querySelector('.list-group').getBoundingClientRect().height;
console.log(this.search_window_height);
});
},
data(){
let allJobListings = JSON.parse(this.job_listings_raw);
return {
searchTerm: '',
jobListings: allJobListings
}
},
computed: {
filteredJobListings(){
return this.jobListings.filter((listing) => {
if(this.searchTerm === ""){
return listing;
}
return listing.title.toLowerCase().indexOf(this.searchTerm.toLowerCase()) >= 0;
});
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment