一、生成天气代码样式
我这里使用的是和风天气的官方链接生成的
https://widget.qweather.com/
这里有个坑,就是你创建的内容使用不了,应该是要收费才能是使用。唯一能使用的就是我下面这个url。
二、天气组件
<template>
<div class="weather">
<div id="he-plugin-standard"></div>
</div>
</template>
<script lang="ts" setup>
import { onMounted } from "vue";
window.WIDGET = {
CONFIG: {
layout: "1",
width: "550",
height: "200",
background: "1",
dataColor: "FFFFFF",
borderRadius: "5",
key: "fcd4fc1e48a144a483b7af74284229b8", //这里使用自己生成的key
},
};
onMounted(() => {
weather();
});
const weather = () => {
const s = document.createElement("script");
s.type = "text/javascript";
s.src = "https://widget.qweather.net/standard/static/js/he-standard-common.js?v=2.0";
document.body.appendChild(s);
};
</script>
<style lang="scss" scoped>
.weather {
width: 60px !important;
height: 100%;
}
</style>
三、引用
<template>
<Weather class="weather"></Weather>
</template>
<script lang="ts" setup>
import Weather from "/@/components/Weather.vue";
</script>
<style lang="scss" scoped>
.weather {
width: 80px;
height: 40px;
}
</style>