[SOLVED] Can't set data () inner value by one of method
-
Hi! Here is part of my scripts:
export default { name: 'Login', data () { return { data: { body: { email: '', password: '', rememberMe: false, auth: { profile: {} <---- ****This is a problem one**** } } }, isPwd: true, loading: false } }, methods: { auth (network) { this.$hello(network).login({ scope: 'email', auth_type: 'rerequest' }) .then((res) => { this.data.body.auth = res['authResponse'] <---- Here everything is ok }) this.getProfile(network) this.$auth.socialLogin(this.data) .then((response) => { this.$router.push({ path: '/account' }) }) .catch((error) => { if (error.response) { if (error.response.status === 401) { this.$q.dialog({ message: this.$t('auth.login.verification_required') }) } else if (error.response.status === 403) { this.$q.notify({ message: this.$t('auth.login.invalid_credentials') }) } else { console.error(error) } } }) }, getProfile (network) { this.$hello(network).api('me') .then((res) => { console.log(res) <---- Here I can see expected json this.data.body.auth.profile = res <--- And here is something wrong console.log(this.data) <--- No profile inside ((( }) },
I have problem with populating of profile. I mark everything in my code. What I’m doing wrong? Thanks for help!
-
It should be
this.body.auth.profile
, shouldn’t it?Scott
-
@s-molinari but why? first upper one works this way…
-
I have no idea why it works. But,
data
isn’t an available property onthis
as you are suggesting. See here.https://codesandbox.io/s/codesandbox-app-k12is
Scott
-
@nobilik move your call to getprofile inside your first then at your auth method or use promise.all, or use async await so its more syncronizingly called. I suggest you read a bit about promises/async awaits.
-
@s-molinari I think you didn’t see data: {} inside data ()
-
You are right. Never mind me then.
Scott
-
@metalsadman Thanks, getprofile inside first then do the job