Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

vue是怎么请求腾讯地图WebService API?

腾讯地图api
我在vue上直接调用
代码如下

import axios from 'axios'
axios.get(`https://apis.map.qq.com/ws/place/v1/search?keyword=酒店&boundary=nearby%2839.908491,116.374328,1000%29&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77`)
        .then(resp =>{
          console.log(resp.data);
        }).catch(err =>{
          console.log(err);
        });

出现报错
image.png

腾讯文档不是说 目前支持JSON/JSONP方式返回 ?
我在vue上直接用axios请求不行吗?
请问路过的高手怎么直接在vue请求成功并获取结果数据,然后在页面上渲染


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

解决方法的是
在vue.config.js
添加几句代码
image.png
然后在vue中使用
image.png
就可以啦
主要是cors使用问题


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...