Skip to content

Instantly share code, notes, and snippets.

@dexcell
Created April 21, 2021 19:28
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 dexcell/1d3c9d9b9a918869600fde318ec964f1 to your computer and use it in GitHub Desktop.
Save dexcell/1d3c9d9b9a918869600fde318ec964f1 to your computer and use it in GitHub Desktop.
Vue.js component transparent wrapper https://youtu.be/7YZ5DwlLSt8?t=1304
<template>
<label>
{{ label }}
<input
v-bind="$attrs"
:value="value"
v-on="listeners"
>
</label>
</template>
<script>
export default {
props: {
label: {
type: String,
default: '',
},
},
data() {
return {
value: '',
};
},
computed: {
listeners() {
return {
...this.$listeners,
input: event => this.$emit('input', event.target.value),
};
},
},
}
</script>
<template>
<div>
<!--
Note how we can use attributes such as placeholder or events such
as @focus despite the fact that we didn't explicitly declared them
in BaseInput.vue
-->
<base-input
label="Search for a game"
placeholder="Type something..."
@focus="onFocus"
@input="onInput"
>
</base-input>
</div>
</template>
<script>
import BaseInput from '../components/BaseInput.vue';
export default {
components: { BaseInput },
methods: {
onFocus() {
alert('Focus');
},
onInput(content) {
console.log(content)
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment