autoHeight.vue 高度自适应
autoHeight.vue 高度自适应
<!--
* @description 自适应高度
* @fileName autoHeight.vue
* @author 彭成刚
* @date 2019/03/11 09:45:38
* @version V1.0.0
<autoHeight v-model="s1Height"
                  :allHeight='0'
                  :precent='20'
                  :diffHeight='0'>
  <table-s1 :height="s1Height"></table-s1>
</autoHeight>
!-->
<template>
  <div :style='styleHeight'>
    <slot></slot>
  </div>
</template>
<script>
export default {
  data () {
    return {
      allHeightData: 0,
      styleHeight: ''
    }
  },
  props: {
    value: {
      type: Number,
      default: 0
    },
    noStyle: {
      type: Boolean,
      default: false
    },
    allHeight: {
      type: Number,
      default: 0
    },
    precent: {
      type: Number,
      default: 100
    },
    diffHeight: {
      type: Number,
      default: 0
    }
  },
  components: {},
  computed: {},
  mounted () {
    this.calcHeight()
    window.addEventListener('resize', () => {
      this.calcHeight()
    })
    // window.innerHeight
  },
  watch: {
    'allHeight' (to, from) {
      this.calcHeight()
    },
    '$route' (to, from) {
      this.calcHeight()
    }
  },
  methods: {
    calcHeight () {
      let retHeight
      if (this.allHeight === 0) {
        this.allHeightData = window.innerHeight
      } else {
        this.allHeightData = this.allHeight
      }
      retHeight = (this.allHeightData * this.precent / 100) - this.diffHeight
      this.$emit('input', retHeight)
      if (!this.noStyle) {
        this.styleHeight = 'height: ' + retHeight + 'px; overflow-y:auto;'
      }
    }
  }
}
</script>
<style lang='less' scoped>
</style>
    ---------------------------------------------
生活的意义就是你自己知道你要做什么,明确目标。没有目标,后面都是瞎扯!
https://pengchenggang.gitee.io/navigator/
SMART原则:
目标必须是具体的(Specific)
目标必须是可以衡量的(Measurable)
目标必须是可以达到的(Attainable)
目标必须和其他目标具有相关性(Relevant)
目标必须具有明确的截止期限(Time-based)
生活的意义就是你自己知道你要做什么,明确目标。没有目标,后面都是瞎扯!
https://pengchenggang.gitee.io/navigator/
SMART原则:
目标必须是具体的(Specific)
目标必须是可以衡量的(Measurable)
目标必须是可以达到的(Attainable)
目标必须和其他目标具有相关性(Relevant)
目标必须具有明确的截止期限(Time-based)

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号