图标下载链接: https://pan.baidu.com/s/1828AidkCKU1KTkw1SvBwQg?pwd=4k7n
共五格信号
信号5为绿色,信号4为绿色,信号3为黄色,信号2为黄色,信号1为红色,信号0为灰色。
子组件
/components/SignalStrength/index.vue
<!-- 信号强度 -->
<template>
<div class="signal-strength">
<img v-if="strength === 5" :src="url5" />
<img v-else-if="strength === 4" :src="url4" />
<img v-else-if="strength === 3" :src="url3" />
<img v-else-if="strength === 2" :src="url2" />
<img v-else-if="strength === 1" :src="url1" />
<img v-else :src="url0" />
</div>
</template>
<script lang="ts">
import signal0 from "/@/assets/signal-0.png"
import signal1 from "/@/assets/signal-1.png"
import signal2 from "/@/assets/signal-2.png"
import signal3 from "/@/assets/signal-3.png"
import signal4 from "/@/assets/signal-4.png"
import signal5 from "/@/assets/signal-5.png"
export default {
name: 'SignalStrength',
props: {
// 信号强度,默认满格信号
strength: {
type: Number,
default: 5,
validator: function (value: number) {
// 必须为不大于5的整数
if (value > 5 || value < 0) {
return false
} else {
return true
}
}
}
},
data() {
return {
url0: signal0,
url1: signal1,
url2: signal2,
url3: signal3,
url4: signal4,
url5: signal5
}
}
}
</script>
<style lang="scss" scoped>
.signal-strength {
width: 16px;
height: 16px;
img {
width: 100%;
height: 100%;
-webkit-user-drag: none;
user-select: none;
}
}
</style>
父组件
strength属性只有5个值,根据信号范围判断
<SignalStrength :strength="1||2||3||4||5" />
效果图