在练习一个vue.js的项目时,通过vue-resource模块中的this.$http方法来获取一个本地的json串
var vm = new Vue({
el:'#shoppingCar',
data:{
title:'购物车'
},
filters:{
},
mounted:function(){
this.cartview();
},
methods:{
cartview:function(){
this.$http.get("data/cartData.json",{"id":123}).then(function(res){
});
}
}
})
结果,报错如下:
Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-resource. |
用npm安装anywhere。
数据通信需要服务器环境,所以需要搭建本地服务器,iis, apache, 或者如果你装了node环境,可以使用anywhere模块。
只要在cmd中输入npm install anywhere -g. 然后cd+工程名, 输入anywhere 就可以了