私は私のメインコンポーネントでこれを使用しました:Vue.jsプロパティは未定義ですか?
<contacts :corporation="corporation"></contacts>
連絡コンポーネント:
export default {
props: {
corporation: {
default:() => []
}
},
data() {
return {
contacts: []
}
},
created() {
this.fetchContacts();
},
methods: {
fetchContacts() {
console.log(this.corporation.slug); // undefined!
CorporationService.users(this.corporation.slug)
.then(({data}) => {
this.contacts = data.contacts;
});
}
}
}
私は連絡コンポーネント内の連絡先を取得しようとしています。問題は、方法fetchContacts();
のconsole.log(this.corporation.slug);
の場合、corporation.slug
は未定義です!
私はvue devtoolsを調べると、法人小道具が適切に設定されています!
何が起こっている可能性がありますか?すでに変更しようとしました:
created() {
this.fetchContacts();
}
を
mounted() {
this.fetchContacts();
}
にしかし、それは働いていません。
親には 'corporation'変数はどのように設定されていますか? – Saurabh
法人:{ default :()=> []なぜあなたはdefaultを関数として定義していますか? –