vue和nvue中控件根據(jù)內(nèi)容自適應大小

圖片.png

自動換行效果如上1,vue默認就會換行顯示,nvue頁面text不能用class必須用style才能自動換行

    <view class="leftView" style="margin-left: 24rpx;">
                        <text class="topText">{{netData.algorithmName}}</text>
                        <text class="midText">{{netData.algorithmCode}}</text>
                        <text class="midText">{{netData.warningTypeName}}</text>
                    </view>
//css
        .leftView {
            display: flex;
            width: 400rpx;
            flex-direction: column;

            .topText {
                width: 400rpx;
                display: flex;
                color: #333333;
                font-family: PingFang SC;
                font-weight: 500;
                font-size: 32rpx;
                word-break: break-all;// 不識別單詞,一行顯示不下默認換行
                word-wrap: break-word;//識別單詞 不會造成單詞斷開換行
                margin-top: 24rpx;
            }
}

內(nèi)容自適應效果圖如上2(注意:display: inline-flex;暫不支持nvue,nvue的display只支持flex)

template

    <view class="bottomTextView">
                        <text class="bottomText">{{netData.productName}}</text>
                    </view>

css

    .bottomTextView {
            margin-left: 24rpx;
            margin-top: 10rpx;
            border-radius: 4rpx;
            margin-bottom: 20rpx;
            background-color: rgb(243, 249, 254);
            display: inline-flex;//關鍵代碼

            .bottomText {
                display: flex;
                font-size: 20rpx;
                padding: 5rpx 10rpx;
                color: #3775f6;
                font-family: PingFang SC;
            }
        }

nvue頁面想要實現(xiàn)上圖2的效果,可以再包裹一層view用overflow: hidden修飾

    <view class="bottomTextBgView">
                        <view class="bottomTextView">
                            <text class="bottomText">{{netData.productName}}</text>
                        </view>
                    </view>
//css
        .bottomTextBgView {
                overflow: hidden;
                display: flex;
                flex-direction: row;
                margin-top: 10rpx;
                margin-bottom: 20rpx;
                margin-left: 24rpx;
            }
            .bottomTextView {
                border-radius: 8rpx;
                align-items: center;
                background-color: rgb(243, 249, 254);
                .bottomText {
                    padding: 5rpx 10rpx;
                    font-size: 20rpx;
                    letter-spacing: 0;
                    font-weight: 500;
                    lines: 1;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    color: #3775f6;
                    font-family: PingFang SC;
                }
            }
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容