尝试使用Vue js发送http get请求。看不到逻辑上的任何问题,但是使用vuejs经验不足。
继续出现以下两个错误:
[Vue警告]:挂接的钩子中出现错误:“ TypeError:无法读取未定义的属性'get'
和
TypeError:无法读取未定义的属性“ get”。
var owm = new Vue({
el: '#owm',
data: {
debug: true,
weather: []
},
methods: {
loadWeather: function() {
this.$http.get('http://api.openweathermap.org/data/2.5/find?q=stockholm&type=like&appid=766b78c39446a8fa6313c3b7b2063ade', function(data, status, request){
if(status == 200)
{
this.weather = data;
console.log(this.weather);
}
});
}
},
mounted: function () {
this.loadWeather();
}
});
Run Code Online (Sandbox Code Playgroud)
使用vue资源更新了代码,错误已消失,但不会控制台记录任何数据,这可能是什么问题?
Vue.use(VueResource);
var owm = new Vue({
el: '#owm',
data: {
weather: []
},
methods: {
loadWeather: function() {
this.$http.get('http://api.openweathermap.org/data/2.5/find?q=stockholm&type=like&appid=[API KEY]', function(data, status, request){
if(status == 200)
{
this.weather …Run Code Online (Sandbox Code Playgroud) 尝试查询 DBpedia 以获取所有国家的列表,其中dbo:longName列出了每个国家的财产和首都,但返回 0 个结果。看不出查询有什么问题。
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?country ?capital
WHERE {
?country a dbo:longName ;
dbo:capital ?capital .
}
Run Code Online (Sandbox Code Playgroud)
少了什么东西?
尝试为数组中的每个对象添加一个 ID。如果 id 已经存在,则 id 会加 1,尝试实现自动递增功能。问题是,使用此函数时,每个对象在 foreach 语句内运行 for 循环时都会获得相同的 ID,或者obj.id of undefined如果循环在外部运行,则无法读取。
function addId(arr, obj) {
obj.id;
arr.forEach(function(obj) {
obj.id = 0;
return obj.id;
});
for(var i = 0; i <= arr.length; i++) {
if(obj.id == obj.id) obj.id++;
}
};
Run Code Online (Sandbox Code Playgroud)