从
vue-mini-weather
迁移过来的基于vue3.x
框架开发,Vite
打包的一款迷你天气预报展示的小组件,目前只支持**大陆的天气预报,原因在更新公告中有,有问题请提issue
-npm // 这个文件夹是上传到npm仓库的,也就是npm i vue3-mini-weather下载的内容就是这个文件夹里的内容
-npm
-src
-lib
...
-public
favicon.ico
-src // 项目源文件,跟npm里的就是少了个App.vue和main.ts而已
-lib
App.vue
main.ts
...
2023.03.10
注意:因为刚上传更新到npm仓库没多久,可能其他镜像源还没有同步过去,所以要下载只能切换npm源。
npm i vue3-mini-weather --save
// 1. 全局引入
//main.js 项目入口文件
import { createApp } from 'vue'
import App from './App.vue'
import weather from 'vue3-mini-weather'
createApp(App).use(weather).mount('#app')
//app.vue 项目文件
<template>
<v-mini-weather>
<template #default="{weather, icon}">
<!--插入图标-->
<v-mini-weather-icon :icon="icon"></v-mini-weather-icon>
<!--DIY内容-->
<span>{{weather.cityname}}/{{weather.weather}}/{{weather.temp}}</span>
</template>
</v-mini-weather>
</template>
// 2. 局部引入
//app.vue 项目文件
<template>
<v-mini-weather>
<template #default="{weather, icon}">
<!--插入图标-->
<v-mini-weather-icon :icon="icon"></v-mini-weather-icon>
<!--DIY内容-->
<span>{{weather.cityname}}/{{weather.weather}}/{{weather.temp}}</span>
</template>
</v-mini-weather>
</template>
<script setup>
import { vMiniWeather, vMiniWeatherIcon } from 'vue3-mini-weather'
</script>
// v-mini-weather参数
url: { // 天气小组件调用的天气查询API
type: String,
default: 'https://apia.aidioute.cn/weather/'
}
// v-mini-weather-icon参数
icon: { // 天气图标编号
type: String,
default: 'd00' // 默认白天-晴
}
type: { // 天气图标类型 -- fill / line
type: String,
default: 'fill'
}
-
版本0.1.2
更新时间:2023.03.10
icon
参数有时候带d
和n
,导致图标组件报错,找不到对应图标,所以不显示,加了个判断,自动加减d
和n
。
-
版本0.1.1
更新时间:2022.11.15
- 从js迁移到ts,添加了.d.ts文件。
- 修改图标比例,之前版本的图标不协调,有些大有些小,重新改了。
v-mini-weather
默认还导出了一个参数icon,直接传给v-mini-weather-icon
就可以了,详见上面的使用方法v-mini-weather-icon
组件添加一个props参数:type
,见上面的参数说明。
-
版本0.1.0
更新时间:2022.10.17
- 从vue-mini-weather迁移过来的,具体内容看vue-mini-weather,这里不再重复赘述。
-
项目使用到了开源的天气动态icon,来源于basmilius
-
获取天气的前提是需要获取您当前的位置信息,默认使用HTML5的定位功能,如果定位失败的话,则采用IP地址定位的方式获取位置信息,再获取天气信息。
Copyright © 2022-present hjiachuang.