白云长空
白云长空
  • 发布:2024-08-08 18:23
  • 更新:2024-08-08 18:23
  • 阅读:108

新手小白提问 请问要怎么样实时更新温湿度数据

分类:uni-app

<template>
<view class="uni-padding-wrap uni-common-mt">

    <unisection>  

        <unicard title="传感数据" :is-shadow="false">  
         <view class="gauge-container">  
            <view class="title">温度</view>  
            <canvas class="canvas" canvas-id="canvas"></canvas>  

            <view class="title">湿度</view>  
            <canvas class="canvas" canvas-id="canvas2"></canvas>  

          </view>  
        </unicard>  

        <view class="uni-title uni-common-pl"></view>  
    </unisection>  

</view>  

</template>

data() {

        return {temp: 25,  
            hum: 50  

        }  
    },  
    mounted() {  
        new Gauge({  
          canvasId: "canvas",  
          width: 200,  
          min: -40,  
          max: 125,  
          value: this.temp,  
          unit: "℃",  
          progressColor: ["#00c800", "#00c800"],  
          showTick: true,  
        });  
        new Gauge({  
          canvasId: "canvas2",  
          min: 0,  
          max: 100,  
          value: this.hum,  
          unit: "%",  
          lineWidth: 10,  
          progressColor: ["#2196F3", "#2196F3"],  

          showTick: true  
        });  
      },  

uni.$on('set_con', (res) => {

            this.temp = uni.getStorageSync('dat_type1')  // 温度  
                             console.log('temp=' + this.temp+"℃")  
            this.hum = uni.getStorageSync('dat_type2')  // 湿度  
            console.log('hum=' + this.hum+"%"  

        })  
2024-08-08 18:23 负责人:无 分享
已邀请:

要回复问题请先登录注册