Ich verwende vue.js in meinem Laravel-Projekt. Das Problem ist, dass vue.js ein leeres Array darstellt, obwohl ich sehe, dass die variablen Namen einige Daten haben.Vue.js2 rendert leeres Array
Ich benutze Laravel 5.4 und vue.js2. Für die jsonp get Methode verwende ich Vue-Ressource
Auch wenn ich meine Variable mit Daten {{names}}
in der Vorlage sehen möchte, fügt es einfach ein leeres Array. In beiden Fällen gibt es keine Fehlerprotokolle.
template.vue
<template>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-body">
{{names}}
</div>
</div>
</div>
</div>
</div>
</template>
Js
<script>
export default {
data: function(){
return {
names: []
};
},
methods: {
getData: function(){
var self = this;
// GET request
this.$http.jsonp(url, {jsonpCallback: "JSON_CALLBACK"})
.then(response=>{
return response.body;
})
.then(data =>{
self.names = data
console.log(JSON.stringify(self.names))// logs the data
})
}
},
mounted() {
this.getData()
console.log('Component mounted.')
}
}
</script>
blade.php
<search id='search'>
</search>
der JSON-Antwort wie folgt aussieht
[
{
"uri":"http://en.wikipedia.org/wiki/Samsung",
"id":"24366",
"type":"org",
"score":527013,
"label":{
"eng":"Samsung"
}
},
{
"uri":"http://en.wikipedia.org/wiki/Samsung_Electronics",
"id":"30860",
"type":"org",
"score":135216,
"label":{
"eng":"Samsung Electronics"
}
}
]
vue Entwickler-Tools zeigen die Variable
dieser meldet alles an? console.log (JSON.stringify (self.names), oder protokolliert es überhaupt? – John
@John ja dieses Protokoll die JSON-Antwort. Deshalb weiß ich, dass die Daten da sind. – Imi
haben Sie vue Devtools? Names Variable zeigt die Ergebnisse dort? – John