组件封装-无数据组件

1. 组件内容

<template>
  <div class="common_nodata_box" :style="{height: height}">
    <div class="common_nodata_bg" :style="{background: `url(${noDataImage}) no-repeat center center`}"></div>
    <span>{{text}}</span>
  </div>
</template>

<script>
import noDataImage from "@/assets/commonNodata.png";
export default {
  name: "commonNoData",
  props: {
    text: {
      type: String,
      default: "抱歉,暂无数据"
    },
    height: {
      type: String // 比如:"600px"
    },
    noDataImage: {
      default: noDataImage
    }
  }
};
</script>

<style lang="less" scoped>
.common_nodata_box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #999999;
  font-size: 14px;
  .common_nodata_bg {
    width: 150px;
    height: 120px;
  }
}
</style>

2. 使用

<template>
  <div>
    <div v-if="hasData">内容</div>
    <CommonNoData v-else height="600px" :noDataImage="require('@/assets/pic-02.png')" text="无数据"></CommonNoData>
  </div>
</template>

<script>
import CommonNoData from "@/components/common-nodata";
export default {
  components: {
    CommonNoData
  },
  data() {
    return {
      hasData: true
    };
  }
};
</script>
posted @ 2020-03-06 15:40  ฅ˙-˙ฅ  阅读(140)  评论(0编辑  收藏  举报