首页 > 其他分享 >VUE~~文字动起来(天气)

VUE~~文字动起来(天气)

时间:2023-11-16 15:32:28浏览次数:25  
标签:文字 VUE const res 天气 item result Date new

图标库:

npm install qweather-icons

@import "qweather-icons/font/qweather-icons.css";

<template>
  <a-spin :spinning="data.loading">
    <div
      style="
        height: 132px;
        padding: 10px 16px 16px 16px;
        background: #fff;
        border: 1px solid rgba(217, 217, 217, 0.4);
        border-radius: 6px;
      "
    >
      <div>
        <span style="font-size: 16px; font-weight: 500">天气情况</span>
        <a href="#" style="float: right">
          <img
            src="/cardapi/route/1008/resource/img/right.png"
            style="width: 14px"
        /></a>
      </div>
      <a-row style="padding-top: 8px">
        <a-col :span="24" style="margin-bottom: 4px">
          <div
            ref="parentBox"
            class="her-label"
            :style="{
              background: warnMess ? '#ff3b3047' : '#E0F2F2',
              color: warnMess ? '#FF3B30' : '#2bada7',
            }"
          >
            <template v-if="!warnMess">
              <img
                src="/cardapi/route/1008/resource/img/safe.png"
                style="width: 16px; position: relative; top: 3px"
              />
              近期无恶劣天气
            </template>
            <template v-else>
              <div ref="aniText" class="top_font aniText">{{ warnMess }}</div>
            </template>
          </div>
        </a-col>
        <a-col
          :span="index == 0 ? 4 : 5"
          v-for="(item, index) in data.values"
          :key="item.fxDate"
          style="text-align: center; line-height: 20px"
        >
          <div>{{ globalFn.formatWeatherData(item.fxDate) }}</div>
          <i
            :class="[
              `qi-${getBoolean(item, 'time') ? item.iconDay : item.iconNight}`,
              'weatherIcon',
            ]"
          ></i>
          <div>{{ item.tempMax }}℃</div>
        </a-col>
      </a-row>
    </div>
  </a-spin>
</template>

<script setup>
import { reactive, ref, getCurrentInstance, nextTick } from "vue";
let data = reactive({
  loading: true,
  values: {},
});
function getBoolean(item, type) {
  if (type == "date") {
    return proxy.globalFn.transitionTimeFn() == new Date(item.fxDate);
  } else {
    return (
      new Date() > new Date(new Date(`${item.fxDate} ${item.sunrise}`)) &&
      new Date() < new Date(new Date(`${item.fxDate} ${item.sunset}`))
    );
  }
}
const { proxy } = getCurrentInstance();
proxy.getApi.getCardData("1008", {}).then((result) => {
  let res = result.data.daily;
  console.log("dd--result--1008", result);
  data.values = res.slice(0, 5);
  data.loading = false;
});
const warnMess = ref();
const aniText = ref(null);
const parentBox = ref(null);
proxy.getApi.getCardData("1009").then((result) => {
  console.log("dd--res--1009", result);
  let res = result.data;
  warnMess.value = res.warning?.[0]?.["text"];
  if (res.warning.length) {
    nextTick(() => {
      const { width } = aniText.value.getBoundingClientRect();
      const { width: parentWidth } = parentBox.value.getBoundingClientRect();
      let indexStep = 0;
      function step(timestamp) {
        //操作
        if (indexStep > width) {
          indexStep = 0;
        }
        aniText.value.style.transform = `translateX(-${(indexStep += 0.1)}px)`;
        requestAnimationFrame(step);
      }
      if (width > parentWidth) {
        requestAnimationFrame(step);
      }
    });
  }
});
</script>
<style>
.weatherIcon {
  color: #0473ff;
}
.top_font {
  display: inline-block;
  white-space: nowrap;
}
.aniText {
  transform: translateX(0px);
}
.her-label {
  padding-left: 10px;
  border-radius: 2px;
  overflow: hidden;
}
</style>

标签:文字,VUE,const,res,天气,item,result,Date,new
From: https://blog.51cto.com/dd118/8425517

相关文章

  • Vue3实战 - 第一章 node.js/npm安装、配置
    一、node.js 安装(windows)1、下载并安装nodehttps://nodejs.org/en安装到 D:\Java\nodes 路径2、配置环境变量检查是否安装成功3、配置全局包存放目录和缓存目录npmconfigsetprefix"D:\nodejs\node_global"npmconfigsetcache"D:\nodejs\node_cache"4、安......
  • 去除:Vue项目打包后生成的.map文件&文件hash值命名
    在vue.config.js文件中设置productionSourceMap和filenameHashing项为false即可。//vue.config.js文件module.exports={outputDir:'dist',assetsDir:'assets',publicPath:'./',//需注意是相对路径,不然dist打包访问后就会出现空白问题。productionSourceMap......
  • vue2组件二次封装
    有时候公共UI组件满足不了一些特定的需求样式,并且有较多地方使用同一个UI组件,这时候就需要考虑二次封装现有UI组件组件二次封装关键的几点:使用$attrs接收props使用$listeners 接收事件使用$slots和$scopedSlots接收插槽使用model定义prop变量及其变化的事件(改变v-mo......
  • gin-vue-admin 接口错误Error: Request failed with status code 500
    本地运行以后登录出现:控制台检查发现是请求getMenu出现500错误,并且后端出现"Error1071(42000):Specifiedkeywastoolong;maxkeylengthis1000bytes"错误,那就是数据库casbin_rule的表引擎不是InnoDB,更改成InnoDB即可。ALTERTABLEcasbin_ruleENGINE=InnoDB;......
  • 投影仪不能显示桌面图标(文字)
    在把笔记本借到投影仪上时,桌面上的图标在投影仪上死活不显示,投影仪只显示笔记本桌面背景,有部分原因如下,希望对大家有所帮助!(1)可能在显示属性里面选择了扩展桌面的选项,如果是这样,投影仪上显示的是扩展的桌面,也就是说你的鼠标可以从你的笔记本屏幕移动到投影仪上,所以桌面图标不......
  • 【vue2】swiper插件自动循环失效(loop失效)
    可能是因为数据是动态渲染的,在请求到数据之前,就已经完成了swiper的初始化,因此解决方案有:1.swiper组件添加v-if:(如以下代码中的v-if="banner.length")<!--轮播图--><div:class="$style.newsBanner"><div:class="$style.swiperBox"><swip......
  • Vue双向数据绑定原理-中
    defineProperty方法defineProperty除了可以动态修改/新增对象的属性以外,还可以在修改/新增的时候给该属性添加get/set方法,从而实现数据劫持。definePropertyget/set方法特点只要通过defineProperty给某个属性添加了get/set方法,那么以后只要获取这个属性的值就会自动调用get,......
  • git拉取项目失败怎么办? 前端vue2 都需要install 什么依赖
    gitconfig--list--show-origin查看git文件下面所有对应文件目录下面是设计配置文件http的缓存大小和那个最低时间和速度gitconfig--globalhttp.lowSpeedTime999999gitconfig--globalhttp.lowSpeedLimit0gitconfig--globalhttp.postBuffer1048576000 ......
  • 若依vue启动报Error: error:0308010C:digital envelope routines::unsupported
    解决:若依vue启动报Error:error:0308010C:digitalenveloperoutines::unsupported1.描述:问题产生原因是因为node.jsV17版本中最近发布的OpenSSL3.0,而OpenSSL3.0对允许算法和密钥大小增加了严格的限制,可能会对生态系统造成一些影响.解决方法:有很多种,我把适合我的写在第一......
  • Vue中Pinia简介
    Pinia是一个进行vue状态管理的组件,他会创建一个带有state、actions、getters的option对象constuseCounterStore=defineStore('counter',{state:()=>({count:0}),getters:{double:(state)=>state.count*2},actions:{increment(){......