springboot+vue项目(day01)

vue 运行npm i 报错:

先看node.js版本 切换版本的工具mac使用n模块

npm install -g n

sudo n 16.4.1   

切换完版本之后要清除一下node_modules

node_modules文件夹
npm cache clean --force 

npm install --legacy-peer-deps

运行

npm run dev

后端

idea打开项目

作为maven

pom

### 关于使用 Spring BootVue 实现天气预报项目的教程 对于构建基于 Spring BootVue 的天气预报应用,虽然提供的参考资料主要集中在用户角色权限管理和安全机制上[^1],可以借鉴这些资料中的前后端交互模式来创建一个新的应用场景——天气预报。 #### 后端服务搭建 (Spring Boot) 为了获取实时天气数据,通常会调用第三方 API 接口。在 Spring Boot 中可以通过 `RestTemplate` 或者更现代的选择如 `WebClient` 来发起 HTTP 请求并处理响应的数据: ```java import org.springframework.web.reactive.function.client.WebClient; // ... public class WeatherService { private final WebClient webClient; public WeatherService(WebClient.Builder webClientBuilder) { this.webClient = webClientBuilder.baseUrl("https://api.weather.com").build(); } public Mono<WeatherResponse> getWeather(String city) { return webClient.get() .uri(uriBuilder -> uriBuilder.path("/v1/geocode/{city}/forecast/daily/7day.json") .queryParam("apiKey", "your_api_key_here") .build(city)) .retrieve() .bodyToMono(WeatherResponse.class); } } ``` 此代码片段展示了如何配置一个简单的 Web 客户端用于请求特定城市的七天天气预测信息。 #### 前端页面展示 (Vue.js) 前端部分则利用 Vue 组件化特性快速渲染接收到的 JSON 数据到 HTML 页面中。下面是一个简化版的例子说明怎样绑定服务器返回的信息至视图层: ```html <!-- src/components/WeatherForecast.vue --> <template> <div v-if="loading">Loading...</div> <ul v-else> <li v-for="(item, index) in forecast" :key="index"> {{ item.date }} - High: {{ item.highTemp }}, Low: {{ item.lowTemp }} </li> </ul> </template> <script> export default { data() { return { loading: true, forecast: null }; }, mounted() { fetch('/weather?city=Beijing') .then(response => response.json()) .then(data => { this.forecast = data.dailyForecasts; this.loading = false; }); } }; </script> ``` 上述组件会在挂载完成后向后端发出 GET 请求以取得北京未来几天内的气温变化情况,并将其呈现给用户查看。 #### 集成与部署 完成以上两步之后还需要考虑跨域资源共享(CORS),确保前后端能够正常通信;另外就是将整个应用程序打包发布上线,在生产环境中稳定运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值