私は以前この "問題"を扱っていましたが、実際に結果を正しく取得する方法は覚えていません。私はHTML側で読み込むことができる変数でいくつかのデータをロードするためにVueの2を使用しています:私はAxios関数スコープ(FC)でconsole.log(response.data)
を記述する場合Vue.js 2&Axiosスコープの問題
window.Vue = require('vue');
window.axios = require('axios');
const app = new Vue({
el: '#app',
data: {
operaciones: [],
sopts: []
},
created: function() {
this.loadOperationTypes();
console.log(this.operaciones); <-- SC
},
methods: {
loadOperationTypes: function() {
axios.post('/api/operaciones')
.then(response => {
console.log(response.data); <-- FC
this.operaciones = response.data
})
.catch(error => {
this.operaciones = error;
});
}
}
});
それは印刷します。
私はcreated_ function() {}
スコープで
console.log(response.data)
を書く場合
はしかし、それは印刷します
axios.post('/api/operaciones')
.then(response => {
console.log(response.data);
app.operaciones = response.data
})
そして
var $this = this;
axios.post('/api/operaciones')
.then(response => {
console.log(response.data);
$this.operaciones = response.data
})
をしかし、任意の手掛かりと同じである:私はすでにこのようなを使用しようとしましたか?
ありがとうございます。
、私は完全に忘れてしまった、私はVueのインスペクタで今すぐチェックし、すべての情報があるようです。ありがとうございました。 – Maramal