登录

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


# 小程序
高洛峰 高洛峰 2717 天前 1123 次浏览

全部回复(2) 我要回复

  • 欧阳克

    欧阳克2016-11-10 15:34:14

    jsonp是跨域的,请求本地写它干嘛 this.$http.get()就行了,具体回调函数看着也有问题 没看你想请求什么数据..response参数也不用

    回复
    0
  • 三叔

    三叔2016-11-10 15:34:01

    必须在http或https协议下才能用AJAX,file协议下浏览器默认禁用AJAX

    回复
    0
  • 取消 回复 发送