美文网首页
Weex textare 自动换行实现(小瑕疵)

Weex textare 自动换行实现(小瑕疵)

作者: fordG | 来源:发表于2020-01-08 11:07 被阅读0次

之前写过一个也是自动换行, 原生实现换行, 针对iOS

  • 闲来无事, 刚好有个小伙伴问我这个实现, 于是研究一番, 用weex来实现了一次,直接上图
image.png
  • 主要利用weex的dom Module来获取text的高度,来动态改变,不过数字,有的时候会算不准, 有想法的可以告诉我!,注意字体需要设置成同意的字体, 要不完全算不准确, 代码如下:
<template>
    <div style="flex: 1; background-color: white; align-items: center; justify-content: center;">
        <textarea :style="{height: inputHeight}" class="textarea" v-model="value" @input="onInput"></textarea>
        <text class="inputText" ref="inputText" style=" background-color: mediumpurple;">{{value}}</text>
    </div>
</template>

<script>

    export default {

        data: {
            value: '',
            inputHeight: 80,
        },

        methods: {
            onInput(e){
                weex.requireModule('dom').getComponentRect(this.$refs.inputText, e=>{
                    if(e.result){
                        console.log(e.value,e.size.height)
                        if(Number(e.size.height) >= 90 || Number(e.size.height)<=200){
                            this.inputHeight = Number(e.size.height)
                        }
                    }
                })
            }
        }
    }
</script>

<style scoped>

    .textarea{
        min-height: 90px;
        max-height: 200px;
        width: 600px;
        border-style: dashed;
        border-width: 1px;
        border-color: #FF0000;
        border-radius: 10px;
        font-size: 32px;
        color: #333333;
        font-family: PingFangSC-Medium;
    }

    .inputText {
        box-sizing: border-box;
        padding: 10.5px;
        min-height: 70px;
        max-height: 200px;
        width: 600px;
        font-size: 32px;
        line-height: 40px;
        color: #333333;
        font-family: PingFangSC-Medium;
    }

</style>

相关文章

  • Weex textare 自动换行实现(小瑕疵)

    之前写过一个也是自动换行, 原生实现换行, 针对iOS 闲来无事, 刚好有个小伙伴问我这个实现, 于是研究一番, ...

  • Weex textarea标签自动换行扩展iOS

    weex 标签扩展 实现WEEX 标签输入框自适应高度 首先贴上我的weex代码: 通过we...

  • weex实现RichText自动换行效果

    weex实现富文本RichText效果 话不错说,先上效果图: 由于最近公司需求,仿微信朋友圈,评论回复@的人需要...

  • pre 自动换行

    pre 标签实现自动换行,在css添加如下属性:

  • EXCEL中的自动换行与自动调整行高

    表现:自动换行本身可实现列宽不变,而自动增加行数;但当行高固定时,行数会增加,行高仍固定。 说明:自动换行调整的对...

  • ReactNative 布局自动换行的实现

    核心思想:基于row布局的wrap属性实现自动换行 效果

  • HTML

    HTML Textarea 自动换行实现 textarea 添加 cols 和 wrap 属性,其中 wrap 设...

  • JXL自动换行的实现

      Java语言中,操作Excel文件比较知名的库有:POI和JXL,我一直使用JXL,通过JXL写文件时,对于同...

  • css列表换行小技巧

    列表一行容不下自动换行 追加内容居右居下! 实现思路1、追加伪类占用位置迫使内容换行,后续内容居右实现效果 htm...

  • 格式处理

    white-space:normal|nowrap(不自动换行)|pre(换行、空格、tab保留住,不允许自动换行...

网友评论

      本文标题:Weex textare 自动换行实现(小瑕疵)

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