美文网首页
封装一个支持v-model的vue组件

封装一个支持v-model的vue组件

作者: HonneyHao | 来源:发表于2019-02-21 09:19 被阅读0次
<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>

相关文章

网友评论

      本文标题:封装一个支持v-model的vue组件

      本文链接:https://www.haomeiwen.com/subject/kfclyqtx.html