Vue3调用高德天气跨域问题的解决

vue3调试时调用高德API获取天气,遇到了跨域。

本项目是vue3,更改vue.config.js

            '/weather': {
                port: 8080,
                target: 'https://restapi.amap.com/v3/weather',
                secure: false,  // 如果是https接口,需要配置这个参数
                changeOrigin: true,  //是否跨域
                pathRewrite: {
                    '^/weather': '/'
                }
            },

vue.config.js配置项如下:

Vue3调用高德天气跨域问题的解决
vue.config.js

调接口如下:

let url = "/weather/weatherInfo" +
    "?key=" + key +
    "&city=" + city +
    "&extensions=" + extensions +
    "&output=" + output;

结果如下:

Vue3调用高德天气跨域问题的解决

参考自:

https://blog.csdn.net/weixin_40169609/article/details/120404984

类似文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注