MarkDirTree.vue 2.1 KB
Newer Older
yma16's avatar
yma16 已提交
1 2
<template>
  <div class="markdown-link">
yma16's avatar
yma16 已提交
3 4 5 6 7 8 9 10 11
    <template  v-if="isExpand">
      <i class="el-icon-s-fold" @click="reverseExpand"  style="color:#ffffff;cursor: pointer;margin-bottom: 10px;float: right">&nbsp;隐藏目录</i>
      <div v-for="(item,index) in content" :key="index">
        <div>
          <template v-for="levelItem in item.level">
            &nbsp;
          </template>
          <span @click="jumpText(item)" class="link-title">{{item.value}}</span>
        </div>
yma16's avatar
yma16 已提交
12
      </div>
yma16's avatar
yma16 已提交
13 14
    </template>
    <i class="el-icon-s-fold" v-else @click="reverseExpand"  style="color:#ffffff;cursor: pointer">&nbsp;显示目录</i>
yma16's avatar
yma16 已提交
15 16 17 18 19 20 21 22 23 24
  </div>
</template>
<script>

export default {
    props: {
        dirContent: undefined
    },
    data () {
        return {
yma16's avatar
yma16 已提交
25 26
            content: '',
            isExpand: true
yma16's avatar
yma16 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
        }
    },
    watch: {
        dirContent: {
            handler (newVal) {
                console.log('newVal', newVal)
                this.content = newVal || ''
            },
            deep: true,
            immediate: true
        }
    },
    mounted () {
        console.log('design vuemarkdown dir')
    },
    methods: {
yma16's avatar
yma16 已提交
43 44 45
        reverseExpand () {
            this.isExpand = !this.isExpand
        },
yma16's avatar
yma16 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        jumpText (item) {
            const {level, value} = item
            console.log(level, value)
            this.herfTo(value)
        },
        herfTo (id) {
            const returnEle = document.querySelector('#' + id) // 获取跳转去的节点
            if (returnEle) {
                returnEle.scrollIntoView(true) // 让当前的元素滚动到浏览器窗口的可视区域内(true:对象的顶端与当前窗口的顶部对齐,false:对象的底端与当前窗口的底部对齐)
            }
        }
    }
}
</script>
<style>
  .markdown-link{
    position: fixed;
yma16's avatar
yma16 已提交
63
    background:rgba(64, 158, 255,.9);
yma16's avatar
yma16 已提交
64 65 66 67
    float: right;
    max-width: 400px;
    padding:20px;
    right:120px;
yma16's avatar
yma16 已提交
68
    top:75px;
yma16's avatar
yma16 已提交
69 70 71 72 73 74 75 76 77 78 79 80
    border-radius: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4);
    transition: 2s;
  }
  .link-title{
    cursor: pointer;
    color: #ffffff;
  }
  .link-title:hover{
    color: #ff995e;
  }
</style>