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>