Skip to content

Instantly share code, notes, and snippets.

@snapwich
Last active January 22, 2018 05:00
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 snapwich/690cf7404cfded46598ba6e714378ac5 to your computer and use it in GitHub Desktop.
Save snapwich/690cf7404cfded46598ba6e714378ac5 to your computer and use it in GitHub Desktop.
<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