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. 老师可以把数据库也给我们吗2. pdo 写入到数据库的内容为中文的时候写入乱码3. 数据库 - 使用读写分离后, MySQL主从复制延迟会导致读不到数据吗?4. PHP类封装的插入数据,总是插入不成功,返回false;5. 二维数组怎么重新组合6. javascript - vue1.0在微信浏览器的兼容性?7. python - 请问为什么csdn登录后,浏览器控制台reponse返回的是空8. 如何使用mysql查询每个用户一次操作时记录的值9. mysql 时间类型 字段(精确到时分秒) 怎么比较?10. thinkphp中Controller里面使用Request::File(’image’);