Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search #252

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const moment = require('moment');
const axiosPath = require('./axiosPath');

const tutorials = [
{
title: 'How to Create a Functioning Search Bar in Vue',
raw: './tutorials/vue/search.md',
url: '/tutorials/vue/search',
description: 'Placeholder Description',
tags: ['vue'],
date: moment('2022-01-11')
},
{
title: 'Handle POST Form Data with Express JS',
raw: './tutorials/express/post-form.md',
Expand Down
136 changes: 136 additions & 0 deletions tutorials/vue/search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
To create a functioning search bar component, do the following:
IslandRhythms marked this conversation as resolved.
Show resolved Hide resolved

<style>
.search-container {
position: relative;
display: flex;
height: 80px;
border-radius: var(--border-radius);
padding-left: 10px;
margin-bottom: 20px;
background-color: white;
}

.search {
display: inline-flex;
flex: 1 1 300px;
cursor: text;
position: relative;
border-radius: 24px;
padding-top: 10px;
padding-bottom: 10px;
padding-left:20px;
padding-right:20px;
margin-right: 10px;
width: 100%;
}

.searchTerm {
outline: none;
color: #9DBFAF;
width: 100%;
padding: .5rem .5rem .5rem 0;
flex: 1;
background-color: var(--text-background-grey)
}

.searchTerm:focus{
color: var(--medium-purple);
}
</style>
<div id = "content"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>
<script>
const app = new Vue({
data: function() {
return {
searchQuery: '',
result: ''
}
},
methods: {
search: async function() {
const res = await fetch(`https://httpbin.org/get?keyword=${this.searchQuery}`).then((res) => {return res.json()});
this.result = Object.values(res.args).find((element) => element.toLowerCase() == this.searchQuery.toLowerCase());
},
},
template: `
<div>
<div class="search-container">
<div class="search">
<input v-model="searchQuery" v-on:keyup.enter="search" type="text" class="searchTerm" placeholder="What are you looking for?" />
</div>
</div>
{{result}}
</div>
`
});
app.$mount("#content");
</script>

```css
IslandRhythms marked this conversation as resolved.
Show resolved Hide resolved
.search-container {
position: relative;
display: flex;
height: 80px;
border-radius: var(--border-radius);
padding-left: 10px;
margin-bottom: 20px;
background-color: white;
}

.search {
display: inline-flex;
flex: 1 1 300px;
cursor: text;
position: relative;
border-radius: 24px;
padding-top: 10px;
padding-bottom: 10px;
padding-left:20px;
padding-right:20px;
margin-right: 10px;
width: 100%;
}

.searchTerm {
outline: none;
color: #9DBFAF;
width: 100%;
padding: .5rem .5rem .5rem 0;
flex: 1;
background-color: var(--text-background-grey)
}

.searchTerm:focus{
color: var(--medium-purple);
}
```

```javascript
Vue.component('search', {
data: function() {
return {
searchQuery: '',
}
},
methods: {
search: async function() {
const res = await fetch(`https://httpbin.org/get?keyword=${this.searchQuery}`).then((res) => {return res.json()});
this.result = Object.values(res.args).find((element) => element.toLowerCase() == this.searchQuery.toLowerCase());
},
},
template: `
<div>
<div class="search-container">
<div class="search">
<input v-model="searchQuery" v-on:keyup.enter="search" type="text" class="searchTerm" placeholder="What are you looking for?" />
</div>
</div>
{{result}}
</div>
`
});
```