Skip to content

Instantly share code, notes, and snippets.

@peterkimzz
Created November 1, 2018 04:35
Show Gist options
  • Save peterkimzz/cbd390c82d6a62c776cacfe2dd34a247 to your computer and use it in GitHub Desktop.
Save peterkimzz/cbd390c82d6a62c776cacfe2dd34a247 to your computer and use it in GitHub Desktop.
Vuejs 자동으로 높이를 조절하는 Textarea
<template>
<textarea
id="textarea"
:placeholder="placeholder"
:value="value"
name="textarea"
@input="input($event.target.value)"/>
</template>
<script>
export default {
props: {
value: {
type: String,
default: ''
},
placeholder: {
type: String,
default: ''
},
autoresize: {
type: [Boolean, String],
default: false
}
},
computed: {
$textarea() {
return document.getElementById('textarea')
}
},
mounted() {
this.init()
},
methods: {
init() {
this.resize()
},
input(value) {
this.$emit('input', value)
this.resize()
},
resize($event) {
if (!this.autoresize) return
this.$textarea.style.height = '1px'
this.$textarea.style.height = `${this.$textarea.scrollHeight + 12}px`
}
}
}
</script>
<style lang="scss" scoped>
@import '~assets/scss/index';
#textarea {
min-height: 50px;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment