vue-resource獲取不到本地json文件的數(shù)據(jù)?
問題描述
<!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()就行了,具體回調(diào)函數(shù)看著也有問題 沒看你想請求什么數(shù)據(jù)..response參數(shù)也不用
回答2:必須在http或https協(xié)議下才能用AJAX,file協(xié)議下瀏覽器默認禁用AJAX
相關(guān)文章:
1. android - Genymotion 微信閃退 not find plugin.location_google.GoogleProxyUI2. mac里的docker如何命令行開啟呢?3. android webview返回自動刷新4. objective-c - iOS開發(fā)使用什么對html進行代碼高亮5. angular.js - 關(guān)于ng-model和ng-bind的疑問6. html - 特殊樣式按鈕 點擊按下去要有凹下和彈起的效果7. angular.js - 在ionic下,利用javascript導入百度地圖,pc端可以顯示,移動端無法顯示8. javascript - 單個控件多個字段搜索9. javascript - npm安裝報錯 系統(tǒng)w7 求大神解答10. html5 - 微信瀏覽器視頻播放失敗
