Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
宝璐
使用和风天气做一个天气页面。 能够显示实时天气数据,
提交
9ccb400a
使
使用和风天气做一个天气页面。 能够显示实时天气数据,
项目概览
宝璐
/
使用和风天气做一个天气页面。 能够显示实时天气数据,
与 Fork 源项目一致
Fork自
清尘27 / VueJS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
使
使用和风天气做一个天气页面。 能够显示实时天气数据,
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9ccb400a
编写于
4月 13, 2023
作者:
6
64374feb3c05b0675a61757e
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto commit
上级
4f39fc67
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
167 addition
and
40 deletion
+167
-40
src/App.vue
src/App.vue
+25
-40
src/components/DemoWeather.vue
src/components/DemoWeather.vue
+142
-0
未找到文件。
src/App.vue
浏览文件 @
9ccb400a
<
script
setup
>
import
HelloWorld
from
'
./components/HelloWorld.vue
'
import
TheWelcome
from
'
./components/TheWelcome.vue
'
</
script
>
<
template
>
<header>
<img
alt=
"Vue logo"
class=
"logo"
src=
"./assets/logo.svg"
width=
"125"
height=
"125"
/>
<div
class=
"wrapper"
>
<HelloWorld
msg=
"You did it!"
/>
<div
id=
"app"
>
<demo-weather></demo-weather>
</div>
</header>
<main>
<TheWelcome
/>
</main>
</
template
>
<
style
scoped
>
header
{
line-height
:
1.5
;
}
<
script
>
.logo
{
display
:
block
;
margin
:
0
auto
2rem
;
}
import
DemoWeather
from
'
./components/DemoWeather.vue
'
;
@media
(
min-width
:
1024px
)
{
header
{
display
:
flex
;
place-items
:
center
;
padding-right
:
calc
(
var
(
--section-gap
)
/
2
);
export
default
{
name
:
'
App
'
,
components
:
{
DemoWeather
},
data
()
{
return
{
active
:
"
vue-home
"
}
.logo
{
margin
:
0
2rem
0
0
;
},
methods
:
{
changePage
(
name
){
this
.
active
=
"
vue-
"
+
name
}
header
.wrapper
{
display
:
flex
;
place-items
:
flex-start
;
flex-wrap
:
wrap
;
}
}
</
script
>
<
style
lang=
"scss"
>
</
style
>
src/components/DemoWeather.vue
0 → 100644
浏览文件 @
9ccb400a
<
template
>
<!-- 天气信息容器 -->
<div
class=
"weather-container"
>
<!-- 天气标题 -->
<h1
class=
"weather-title"
>
{{
cityName
}}
实时天气数据
</h1>
<!-- 天气信息展示 -->
<div
class=
"weather-info"
>
<!-- 天气信息项 -->
<div
class=
"weather-item"
v-for=
"(item, index) in weatherData"
:key=
"index"
>
<!-- 天气信息标签 -->
<p
class=
"weather-label"
>
{{
item
.
label
}}
:
</p>
<!-- 天气信息值 -->
<p
class=
"weather-value"
>
{{
item
.
value
}}
</p>
</div>
</div>
<!-- 城市输入框 -->
<div
class=
"input-container"
>
<input
type=
"text"
v-model=
"locations"
placeholder=
"请输入城市名"
@
change=
"getWeatherData"
>
</div>
</div>
</
template
>
<
script
>
export
default
{
data
:
function
()
{
return
{
// 城市名
cityName
:
''
,
// 天气信息
weatherData
:
[],
// 默认城市
locations
:
'
杭州
'
};
},
mounted
()
{
// 获取天气信息
this
.
getWeatherData
();
},
methods
:
{
// 获取天气信息
getWeatherData
()
{
// 获取城市信息
fetch
(
`https://geoapi.qweather.com/v2/city/lookup?location=
${
this
.
locations
}
&key=b8eab9bbc51c4173b92519ae8c6dfde5`
)
.
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
const
location
=
data
.
location
[
0
];
// 更新城市名
this
.
cityName
=
location
.
name
;
// 获取天气信息
fetch
(
`https://devapi.qweather.com/v7/weather/now?location=
${
location
.
id
}
&key=b8eab9bbc51c4173b92519ae8c6dfde5`
)
.
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
const
now
=
data
.
now
;
// 更新天气信息
this
.
weatherData
=
[
{
label
:
'
实时温度
'
,
value
:
now
.
temp
},
{
label
:
'
体感温度
'
,
value
:
now
.
feelsLike
},
{
label
:
'
风力风向
'
,
value
:
`
${
now
.
windDir
}
${
now
.
windScale
}
级`
},
{
label
:
'
相对湿度
'
,
value
:
`
${
now
.
humidity
}
%`
},
{
label
:
'
大气压强
'
,
value
:
`
${
now
.
pressure
}
百帕`
},
{
label
:
'
降水量
'
,
value
:
`
${
now
.
precip
}
毫米`
},
{
label
:
'
能见度
'
,
value
:
`
${
now
.
vis
}
公里`
},
{
label
:
'
露点温度
'
,
value
:
`
${
now
.
dew
}
℃`
},
{
label
:
'
云量
'
,
value
:
`
${
now
.
cloud
}
%`
}
];
});
});
}
}
};
</
script
>
<
style
scoped
>
/* 天气信息容器 */
.weather-container
{
display
:
flex
;
flex-direction
:
column
;
align-items
:
center
;
justify-content
:
center
;
height
:
100%
;
}
/* 天气标题 */
.weather-title
{
font-size
:
2rem
;
margin-bottom
:
2rem
;
}
/* 天气信息展示 */
.weather-info
{
display
:
flex
;
flex-wrap
:
wrap
;
justify-content
:
center
;
}
/* 天气信息项 */
.weather-item
{
display
:
flex
;
flex-direction
:
column
;
align-items
:
center
;
margin
:
1rem
;
padding
:
1rem
;
border-radius
:
10px
;
box-shadow
:
0
0
10px
rgba
(
0
,
0
,
0
,
0.2
);
background-color
:
#fff
;
color
:
#333
;
font-size
:
1.2rem
;
text-align
:
center
;
min-width
:
150px
;
}
/* 天气信息标签 */
.weather-label
{
font-weight
:
bold
;
}
/* 天气信息值 */
.weather-value
{
margin-top
:
0.5rem
;
}
/* 城市输入框 */
.input-container
{
margin-top
:
2rem
;
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
}
/* 输入框样式 */
input
[
type
=
"text"
]
{
padding
:
0.5rem
;
border-radius
:
5px
;
border
:
none
;
box-shadow
:
0
0
10px
rgba
(
0
,
0
,
0
,
0.2
);
font-size
:
1.2rem
;
width
:
300px
;
text-align
:
center
;
}
</
style
>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录