当前位置:   article > 正文

Tree 样式多元化

tree 样式

在这里插入图片描述

<template>
    <Tree :data="data" :render="renderContent" class="demo-tree-render"></Tree>
</template>
<script>
    import { resolveComponent } from 'vue'
    export default {
        data () {
            return {
                data: [
                    {
                        title: 'parent 1',
                        expand: true,
                        render: (h, { root, node, data }) => {
                            return h('span', {
                                style: {
                                    display: 'inline-block',
                                    width: '100%'
                                }
                            }, [
                                h('span', [
                                    h(resolveComponent('Icon'), {
                                        type: 'ios-folder-outline',
                                      
                                        style: {
                                            marginRight: '8px'
                                        }
                                    }),
                                    h('span', data.title +'(59/62)')
                                ]),
                               
                            ]);
                        },
                        children: [
                            {
                                title: 'child 1-1',
                                expand: true,
                              	levle:2,
                                children: [
                                    {
                                        title: 'leaf 1-1-1',
                                        expand: true,
                              	levle:3
                                    },
                                    {
                                        title: 'leaf 1-1-2',
                                        expand: true,
                              	levle:3
                                    }
                                ]
                            },
                            {
                                title: 'child 1-2',
                                expand: true,
                              	levle:2,
                                children: [
                                    {
                                        title: 'leaf 1-2-1',
                                        expand: true,
                              	levle:3
                                    },
                                    {
                                        title: 'leaf 1-2-1',
                                        expand: true,
                              	levle:3
                                    }
                                ]
                            }
                        ]
                    }
                ],
                buttonProps: {
                    type: 'default',
                    size: 'small',
                }
            }
        },
        methods: {
            renderContent (h, { root, node, data }) {              
               if(data.levle == 2){
                      return h('span', {
                                style: {
                                    display: 'inline-block',
                                    width: '100%'
                                }
                            }, [
                                h('span', [
                                    h(resolveComponent('Icon'), {
                                         type: 'ios-pin',  
                                        style: {
                                            marginRight: '8px',
                                          color:'blue'||'gray'
                                        }
                                    }), 
                                       h('span', {},data.title ), 
                                       h('div', { style: {
                                            display: 'inline-block',
                                            width: '100%'
                                        }},[
                                         h('span', {},'('),
                                           h('span', { style: {
                                             color:'#f00' 
                                          }},56), 
                                         h('span', {},'/'),
                                         h('span', {},89), 
                                         h('span', {},')'),
                                       ] ),
                                ]),
                               
                            ]);
              }else{
                return h('span', {
                    style: {
                        display: 'inline-block',
                        width: '100%'
                    }
                }, [
                    h('span', [
                        h(resolveComponent('Icon'), {
                            type: 'ios-paper-outline',
                            style: {
                                marginRight: '8px'
                            }
                        }),
                        h('span', data.title),
                      	h('span', { style: {
														background:'#0f0',                     
                          color:'#fff',
                          padding:'1px 2PX',
                          borderRadius:'4px',
                            marginLeft: '4px'
                        }},'验'), 
                      h('span', { style: {
														background:'#0f0',                     
                          color:'#fff',
                          padding:'1px 2PX',
                          borderRadius:'4px',
                            marginLeft: '4px'
                        }},'考'), 
                        h('span', { style: {
														background:'#0f0',                     
                          color:'#fff',
                          padding:'1px 2PX',
                          borderRadius:'4px',
                            marginLeft: '4px'
                        }},'国'), 
                    ]),
                    
                ]);
              }
         
            },
            append (data) {
                const children = data.children || [];
                children.push({
                    title: 'appended node',
                    expand: true
                });
                data.children = children
            },
            remove (root, node, data) {
                const parentKey = root.find(el => el === node).parent;
                const parent = root.find(el => el.nodeKey === parentKey).node;
                const index = parent.children.indexOf(data);
                parent.children.splice(index, 1);
            }
        }
    }
</script>
<style>
    .demo-tree-render .ivu-tree-title{
        width: 100%;
    }
</style>



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/322323
推荐阅读
相关标签
  

闽ICP备14008679号