本身写了一个json数据,放在服务器上,如今要经过vue项目调用数据vue
http://www.intmote.com/test.jsonwebpack
我如今要调用git
在调用接口数据的时候的时候
会出现这样的报错github
Access to XMLHttpRequest at 'http://www.intmote.com/test.json' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这个时候,是遇到了跨域的问题; 因为接口跨域问题,所以不能直接经过ajax请求访问web
查看本身的代码,直接把json接口写在请求里ajax
1:打开build/webpack.dev.conf.js,配置代理proxyTable属性以下:经过vue-cli提供给的代理(proxy)进行配置便可,vue-cli
proxyTable: { '/api': { target: 'http://www.intmote.com', changeOrigin: true, pathRewrite: { '^/api': '' } } },
2:回到当前页面,个人页面是my.vue,修改请求路径json
created() { this.$http.get('/api/test.json').then((response) => { console.log(response.data) //响应正确回调 this.nameList = response.body; //把数据存放到data中 }) },
3:从新启动项目api
4:这个时候能够看到,跨域问题解决
json里面的数据也显示在了页面里面跨域
github访问连接:https://github.com/wangxiaoting666/mint-demo
Vue移动端框架Mint UI教程-搭建环境引入框架(一)
https://www.jianshu.com/p/874e5152b3c5
Vue移动端框架Mint UI教程-底部导航栏(二)
https://www.jianshu.com/p/56e887cbb660
Vue移动端框架Mint UI教程-组件的使用(三)
https://www.jianshu.com/p/5ec1e2d2f652
Vue移动端框架Mint UI教程-跳转新页面(四)
https://www.jianshu.com/p/364d0462ddb6
Vue移动端框架Mint UI教程-调用模拟json数据(五)
https://www.jianshu.com/p/6d3f1436b327
Vue移动端框架Mint UI教程-数据渲染到页面(六)
https://www.jianshu.com/p/dc532ab82d2a
Vue移动端框架Mint UI教程-接口跨域问题(七)
https://www.jianshu.com/p/b28cd8290b2a