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é)議下瀏覽器默認(rèn)禁用AJAX
相關(guān)文章:
1. windows誤人子弟啊2. 冒昧問一下,我這php代碼哪里出錯了???3. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)4. python - linux怎么在每天的凌晨2點(diǎn)執(zhí)行一次這個log.py文件5. 數(shù)據(jù)庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實(shí)在是找不到哪里的問題了。6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. mysql優(yōu)化 - MySQL如何為配置表建立索引?8. 如何用筆記本上的apache做微信開發(fā)的服務(wù)器9. 我在網(wǎng)址中輸入localhost/abc.php顯示的是not found是為什么呢?10. 關(guān)于mysql聯(lián)合查詢一對多的顯示結(jié)果問題
