vue-resource获取不到本地json文件的数据?
问题描述
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>菜鸟</title> <script src="js/vue.js"></script> <script src="js/vue-resource.min.js"></script> <link href="example.css" rel="stylesheet" type="text/css" /></head><body><div id="example"> <button id="but" >添加</button> <ul id="example1"><li v-for="item in items"> {{ item.id }} {{ item.author }} </li> </ul> </div><script> //在这里面写Vue.js代码var example = new Vue({ el: '#example', data: { items: [ { id:'0',author:'我'} ] }, ready:function(){ this.$http.jsonp('1.json',{},{headers:{},emulateJSON: true }).then(function(response){alert('123'); },function(response){}); }}) //----------------</script></body></html>//浏览器无法弹出123
问题解答
回答1:jsonp是跨域的,请求本地写它干嘛 this.$http.get()就行了,具体回调函数看着也有问题 没看你想请求什么数据..response参数也不用
回答2:必须在http或https协议下才能用AJAX,file协议下浏览器默认禁用AJAX
相关文章:
1. docker不显示端口映射呢?2. python相关问题求解决,有偿3. javascript - vue2.0中使用vue2-dropzone的demo,vue2-dropzone的github网址是什么??百度不到。4. node.js - nodejs+express+vue5. node.js - 如何调用hexo渲染 ``` ``` 代码块的渲染引擎6. android - 安卓activity无法填充屏幕7. jquery - css3 scale 缩放图片问题8. html5 - iOS的webview加载出来的H5网页,怎么修改html标签select的样式字体?9. javascript - 怎么用flatlist替换scrollview?10. javascript - 使用webStorm通过git提交代码push时报错

网公网安备