iview的table中Tooltip的使用


這篇文章主要介紹了iview-admin中在table中使用Tooltip提示效果。

1. table中文字溢出隱藏,提示氣泡展示所有信息

jLongText(item){
    item.render = (h, params)=>{
        // 處理文字,溢出用點代替
        let txt = params.row[params.column.key]
        let tableTxt = null
        if(txt){
            if(txt.length > item.longText){
                tableTxt = txt.substring(0, item.longText) + '.....'
            }else{
                tableTxt = txt
            }
        }
        
        return h('Tooltip', {
            props: {
                placement: 'top'
            }
        },[
            tableTxt,
            h('span', {slot: 'content', style: {whiteSpace: 'normal', wordBreak: 'break-all'}}, txt)
        ])
    }
    return item
},
// style是 必須的,否則無法換行顯示

2. Tooltip 折行顯示效果

{
    title: '狀態監控',
    align: 'center',
    key: 'stat'
    render: (h, params) => {
        return h('Tooltip', {
            props: {
                placement: "right"
            }
        },[
            stat,
            [
                h('p', { slot: 'content'},'CPU:11.1%'),
                h('p', { slot: 'content'},'內存:5/12GB')
            ]
        ]);
    }
}
// 使用多個標簽實現多行顯示,而不是換行

3. 單獨使用Tooltip實現折行效果

<!-- 注意 Tooltip 內的文本使用了 white-space: nowrap;,即不自動換行,如需展示很多內容並自動換行時,建議給內容 slot 增加樣式 white-space: normal; -->
<Tooltip :disabled="!msg">
    <div slot="content" style="white-space:normal">{{msg}}</div>
    <Input v-model="msg" />
</Tooltip>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM