VueJSを学び、部品ロード時に簡単なAPIコールを実行して、reposのリストをページに配置しようとしています。 created()
メソッドからthis.repos
を呼び出して設定すると、問題はありません。しかし、方法として設定してからthis.getRepos
から呼び出すと何も起こりません。エラーなし、何もありません。私はVueJSについて何が欠けていますか?VueJSがcreated()関数からメソッドを呼び出さないのはなぜですか?
これは動作します:
data:() => ({
msg: 'Github Repos',
ok: 'Im practically giving away these repos',
repos: [],
}),
methods: {
},
async created() {
const repos = await axios.get('https://api.github.com/orgs/octokit/repos');
this.repos = repos.data.map(repo =>
`<div class="box"><a href="${repo.html_url}">
${repo.name}
</div>`,
);
},
これは動作しません:
data:() => ({
msg: 'Github Repos',
ok: 'Im practically giving away these repos',
repos: [],
}),
methods: {
getRepos: async() => {
const repos = await axios.get('https://api.github.com/orgs/octokit/repos');
this.repos = repos.data.map(repo =>
`<div class="box"><a href="${repo.html_url}">
${repo.name}
</div>`,
);
},
},
created() {
this.getRepos();
},
任意のアイデア?ありがとう!
[VueJSの可能性の重複:なぜ "この" 定義されていませんか? ](https://stackoverflow.com/questions/43929650/vuejs-why-is-this-undefined) – Bert
ちょうど 'async getRepos(){' – Reiner