Created
April 21, 2021 19:28
-
-
Save dexcell/1d3c9d9b9a918869600fde318ec964f1 to your computer and use it in GitHub Desktop.
Vue.js component transparent wrapper https://youtu.be/7YZ5DwlLSt8?t=1304
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> | |
<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> |
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> | |
<!-- | |
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