封装一个支持v-model的vue组件
2019-02-21 本文已影响0人
HonneyHao
<template>
<div>
<el-input
type="textarea"
:maxlength="len"
autosize
placeholder="请输入内容"
:value="value"
@input="changeInput"
></el-input>
<p>{{num}}/{{len}}</p>
</div>
</template>
<script>
export default {
data() {
return {
num:0,
len:150
}
},
props:{
value:String||Number//这里要在props里面写值
},
methods: {
注意此处//
changeInput(e){
this.num=e.length;
this.$emit('input', e)
}
},
}
</script>
<style lang="less" scoped>
</style>