Last active
January 22, 2018 05:00
-
-
Save snapwich/690cf7404cfded46598ba6e714378ac5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<template> | |
<div class="google-search"> | |
<button @click="search(text)"> | |
<i class="fa fa-search"></i> | |
</button> | |
<input ref="input" | |
title="Site Search" | |
v-on:keyup.13="search(text)" | |
v-model="text" /> | |
</div> | |
</template> | |
<script> | |
export default { | |
props: [ | |
'site' | |
], | |
data() { | |
return { | |
text: '' | |
} | |
}, | |
methods: { | |
search(str) { | |
if (str) { | |
window.open([ | |
'https://www.google.com/search?q=', | |
this.site ? 'site:' + this.site + '+' : '', | |
encodeURIComponent(str) | |
].join('')); | |
} else { | |
this.$refs.input.focus(); | |
} | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment