Advertisement
Guest User

Search.vue

a guest
Jan 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <template>
  2. <div class="hello">
  3. <h1>Search</h1>
  4. <input v-model="term" type="search"> <button @click="search">Search</button>
  5. <div v-if="results">
  6. <ul>
  7. <li v-for="result in results" :key="result.Link">
  8. <a :href="result.Link" target="_new">{{result.API}}</a> - {{result.Description}}
  9. </li>
  10. </ul>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'Search',
  17. data() {
  18. return {
  19. term:'',
  20. results:null
  21. }
  22. },
  23. methods: {
  24. search() {
  25. if(this.term.trim() === '') return;
  26. console.log('search for '+this.term);
  27. fetch(`https://api.publicapis.org/entries?title=${encodeURIComponent(this.term)}`)
  28. .then(res => res.json())
  29. .then(res => {
  30. console.log('results', res);
  31. this.results = res.entries;
  32. });
  33. }
  34. }
  35. }
  36. </script>
  37. <!-- Add "scoped" attribute to limit CSS to this component only -->
  38. <style scoped></style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement