网页中天气显示

我们常常会看到在网页中的导航栏处有一个天气的显示
在这里插入图片描述
这样的一个效果是通过一些第三方天气插件实现的 ,这里为大家讲解的是html实现和vue实现

这里的插件是从天气网插件找到的 天气插件网

HTML实现

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="weather-v2-plugin-simple"></div>
    <script>
        WIDGET = {
            CONFIG: {
                "modules": "01234",
                "background": 1,
                "tmpColor": "FFFFFF",
                "tmpSize": 16,
                "cityColor": "FFFFFF",
                "citySize": 16,
                "aqiSize": 16,
                "weatherIconSize": 24,
                "alertIconSize": 18,
                "padding": "10px 10px 10px 10px",
                "shadow": "1",
                "language": "auto",
                "borderRadius": 5,
                "fixed": "false",
                "vertical": "middle",
                "horizontal": "center",
                "key": "GZKlqrzaXZ"
            }
        }
    </script>
    <script src="https://apip.weatherdt.com/simple/static/js/weather-simple-common.js?v=2.0"></script>
</body>

</html>

Vue实现

<template>
  <div>
	<div id="weather-v2-plugin-simple"></div>
  </div>
</template>

<script>
  export default {
    name: "Nav",
    data() {
      return {};
    },
    created() {

    },
    mounted() {
      // 天气插件
      window.WIDGET = {
        CONFIG: {
          modules: "01234",
          background: 1,
          tmpColor: "FFFFFF",
          tmpSize: 16,
          cityColor: "FFFFFF",
          citySize: 16,
          aqiSize: 16,
          weatherIconSize: 24,
          alertIconSize: 18,
          padding: "10px 10px 10px 10px",
          shadow: "1",
          language: "auto",
          borderRadius: 5,
          fixed: "false",
          vertical: "middle",
          horizontal: "center",
          key: "GZKlqrzaXZ"
        }
      };
      (function (d) {
        var c = d.createElement("link");
        c.rel = "stylesheet";
        c.href =
          "https://apip.weatherdt.com/simple/static/css/weather-simple.css?v=2.0";
        var s = d.createElement("script");
        s.src =
          "https://apip.weatherdt.com/simple/static/js/weather-simple.js?v=2.0";
        var sn = d.getElementsByTagName("script")[0];
        sn.parentNode.insertBefore(c, sn);
        sn.parentNode.insertBefore(s, sn);
      })(document);
    },
    methods: {
    }
  }
</script>

<style scoped>

</style>

除了这种方式还有就是可以使用iframe实现

<iframe width="500" height="40" frameborder="0" scrolling="no" hspace="0" src="https://i.tianqi.com/?c=code&a=getcode&id=40&icon=1"></iframe>

另外一个免费的天气插件网

https://widget.qweather.com/create-simple

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值