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. docker不顯示端口映射呢?3. java - 阿里的開發手冊中為什么禁用map來作為查詢的接受類?4. python - django 使用 redirect 跳轉網頁,怎么傳遞 referer 給目標網頁5. python - SQLAlchemy 向對應的id插入數據怎么操作?6. 網頁爬蟲 - python 爬蟲怎么處理json內容7. javascript - 微信小程序電商務搜索頁排序功能的邏輯8. python - flask用ajax做后臺登陸交互,驗證密碼后,如何重新定位到index.html上?9. python中def定義的函數加括號和不加括號的區別?10. mysql 新增用戶 主機名設定 失敗
