vue实现展开影藏插件(转载)

Posted ivangitz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue实现展开影藏插件(转载)相关的知识,希望对你有一定的参考价值。

转自https://segmentfault.com/q/1010000011359250/a-1020000011367096

创建了一个函数式组件

const elTransition = ‘0.3s height ease-in-out, 0.3s padding-top ease-in-out, 0.3s padding-bottom ease-in-out‘
const Transition = {
  ‘before-enter‘ (el) {
    el.style.transition = elTransition
    if (!el.dataset) el.dataset = {}

    el.dataset.oldPaddingTop = el.style.paddingTop
    el.dataset.oldPaddingBottom = el.style.paddingBottom

    el.style.height = 0
    el.style.paddingTop = 0
    el.style.paddingBottom = 0
  },

  ‘enter‘ (el) {
    el.dataset.oldOverflow = el.style.overflow
    if (el.scrollHeight !== 0) {
      el.style.height = el.scrollHeight + ‘px‘
      el.style.paddingTop = el.dataset.oldPaddingTop
      el.style.paddingBottom = el.dataset.oldPaddingBottom
    } else {
      el.style.height = ‘‘
      el.style.paddingTop = el.dataset.oldPaddingTop
      el.style.paddingBottom = el.dataset.oldPaddingBottom
    }

    el.style.overflow = ‘hidden‘
  },

  ‘after-enter‘ (el) {
    el.style.transition = ‘‘
    el.style.height = ‘‘
    el.style.overflow = el.dataset.oldOverflow
  },

  ‘before-leave‘ (el) {
    if (!el.dataset) el.dataset = {}
    el.dataset.oldPaddingTop = el.style.paddingTop
    el.dataset.oldPaddingBottom = el.style.paddingBottom
    el.dataset.oldOverflow = el.style.overflow

    el.style.height = el.scrollHeight + ‘px‘
    el.style.overflow = ‘hidden‘
  },

  ‘leave‘ (el) {
    if (el.scrollHeight !== 0) {
      el.style.transition = elTransition
      el.style.height = 0
      el.style.paddingTop = 0
      el.style.paddingBottom = 0
    }
  },

  ‘after-leave‘ (el) {
    el.style.transition = ‘‘
    el.style.height = ‘‘
    el.style.overflow = el.dataset.oldOverflow
    el.style.paddingTop = el.dataset.oldPaddingTop
    el.style.paddingBottom = el.dataset.oldPaddingBottom
  }
}

export default {
  name: ‘collapseTransition‘,
  functional: true,
  render (h, { children }) {
    const data = {
      on: Transition
    }
    return h(‘transition‘, data, children)
  }
}

html部分

<!-- 隐藏部分
  -------------------------- --> 
  <collapse-transition>
     <div class="collapse-wrap"
       v-show="isActive">
      <!-- @slot default -->
      <slot></slot>
    </div> 
  </collapse-transition>

以上是关于vue实现展开影藏插件(转载)的主要内容,如果未能解决你的问题,请参考以下文章

从零开始配置vim(27)——代码片段

从零开始配置vim(27)——代码片段

从零开始配置vim(27)——代码片段

vscode代码片段生成vue模板

vue实现收起展开面板

时间轴组件(Vue+element)