私は要素UIでVue.jsを使用しています。私はVue Jsコールを手にしました
Expected Array, got Object.
私は「取得」コールが単一の約束オブジェクトを返すされていることを理解:私はまだ、私は次のエラーで捕まってしまったテーブルを埋めるために持っています。私は配列に到達する方法を見てそのオブジェクトを印刷しようとしました。それは[[PromiseValue]]の中にあり、私はそれにアクセスする方法を知らない。私はこの記事の答えを見た:What does [[PromiseValue]] mean in javascript console and how to do I get it。しかしそれはそれが個人的な財産であるので、そうした方法でそれにアクセスしているようには思われませんでした。だから私は標準的な解決策を探しています。これはvue.jsの私の最初のプロジェクトです。私は前に角度2-4を使用し、私はちょうどresponse.json()._embedded.customers
を呼び出す取得行うために必要な:
this.$http.get('http://localhost:8080/customers')
.then(response => {
// JSON responses are automatically parsed.
this.customersArray = response.json();
console.log(response.json());
})
.catch(function(err) {
return {
name: 'default user'
};
})
を、私が必要お客様の下に配列。 crudの場合、vueリソースが使用されています。
編集:次のように私はそれを解決するためにも試してみましたが、私は、スクリーンショットのと同じ結果を得た:
var promise1 = new Promise((resolve, reject) => {
Vue.http.get('http://localhost:8080/customers').then((response) => {
resolve(response.json());
}, (response) => {
reject(response.status)
})
});
console.log(promise1);
はお時間をいただき、ありがとうございます。
あなたは 'this.customersArray = response.json()['_ embedded'] ['customers']'を試したことがありますか? – Hipny
私はあなたが言ったように試みました、それは私にエラーを与えませんが、メソッドから終了します。私はcustomersArrayに割り当てた直後に、response.json()['_ embedded'] ['customers']を出力しようとしたconsole.log(...)を読みません。どちらもテーブルをいっぱいにしません。 –
プロミスは非同期です。つまり、console.logが実行されると、リクエストはまだ完了していない可能性があります。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise – Hipny