How to access a mapAction method using Vuejs?
up vote
1
down vote
favorite
Regards,
I would like to know how I can access the logOut function that comes from mapActions,
What I do not understand is how it is possible, that with the logIn function when I refer to it, it works for me but with the function of logOut no.
Here is the error: Uncaught ReferenceError: logOut is not defined
Here I leave the code:
<template>
<div class="home">
<v-card height="200px" flat dark app>
<div class="headline text-xs-center pa-5">
Active: bottomNav
</div>
<v-bottom-nav :active.sync="bottomNav" :value="true" absolute color="transparent">
<v-btn color="teal" flat value="messages">
<span>Messages</span>
<v-icon>chat</v-icon>
</v-btn>
<v-btn color="teal" flat value="notifications">
<span>Notifications</span>
<v-icon>notifications</v-icon>
</v-btn>
<v-btn color="red" @click.prevent="logIn()" flat value="logIn">
<span>LogIn</span>
<v-icon>whatshot</v-icon>
</v-btn>
<v-menu offset-y origin="center center" :nudge-bottom="10" transition="scale-transition">
<v-btn icon large flat slot="activator">
<v-avatar size="30px">
<img src="../assets/logo.png" alt="user-logo"/>
</v-avatar>
</v-btn>
<v-list class="pa-0">
<v-list-tile v-for="(item , index) in items"
:to="!item.href ? name: item.name : null"
:href="item.href"
@click.prevent="item.click"
ripple="ripple"
:disabled="item.disabled"
:target="item.target"
rel="noopener"
:key="index"
ref="myBtn"
>
<v-list-tile-action v-if="item.icon">
<v-icon> item.icon </v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title> item.title </v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-menu>
</v-bottom-nav>
</v-card>
<script>
import mapActions, mapState from 'vuex';
export default
name: 'home',
computed: mapState(['data' , 'loading']),
data()
return
bottomNav: 'LogIn',
items: [
icon: 'account_circle',
href: '#',
title: 'Profile',
click: ''
,
icon: 'settings',
href: '#',
title: 'Settings',
click: ''
,
icon: 'fullscreen_exit',
href: '#',
title: 'Logout',
click: () =>
this.logOut();
]
,
methods:
...mapActions(['logIn' , 'logOut']),
,
</script>
Actions.js
Im getting this error: Uncaught TypeError: Cannot set property 'data' of undefined this error is pointing to the mutation file in the UPDATE_DATA.
import GROUP_ID from '../config/env';
export const actions =
logIn(state , commit)
FB.login((res) =>
console.log(res);
if(res.status == "connected")
state.user.id = res.authResponse.userID;
state.user.accessToken = res.authResponse.accessToken;
console.log("user:%sntoken:%s" , state.user.id , state.user.accessToken);
FB.api('/me' , (res) =>
this.user.username = res.authResponse.name;
);
FB.api(`/$GROUP_ID/feed`,'GET', (res) =>
if(res && !res.error)
res['data'].forEach((data) =>
console.log("api connection => " , data);
commit('UPDATE_DATA' , data);
commit('IS_LOADING_DATA' , false);
);
);
,scope:'public_profile, email, groups_access_member_info');
,
logOut(state)
console.log(state.user.accessToken);
try
if(FB.getAccessToken() != null)
FB.logout(function(res)
console.log("User is logged out");
console.log(res);
);
else
console.log("User is not logged in");
catch(err)
console.log(err);
Mutations.js
export const mutations =
UPDATE_DATA(state , payload)
state.data = payload;
,
IS_LOADING_DATA(state , payload)
state.loading = payload;
javascript vue.js web-deployment vuex
|
show 2 more comments
up vote
1
down vote
favorite
Regards,
I would like to know how I can access the logOut function that comes from mapActions,
What I do not understand is how it is possible, that with the logIn function when I refer to it, it works for me but with the function of logOut no.
Here is the error: Uncaught ReferenceError: logOut is not defined
Here I leave the code:
<template>
<div class="home">
<v-card height="200px" flat dark app>
<div class="headline text-xs-center pa-5">
Active: bottomNav
</div>
<v-bottom-nav :active.sync="bottomNav" :value="true" absolute color="transparent">
<v-btn color="teal" flat value="messages">
<span>Messages</span>
<v-icon>chat</v-icon>
</v-btn>
<v-btn color="teal" flat value="notifications">
<span>Notifications</span>
<v-icon>notifications</v-icon>
</v-btn>
<v-btn color="red" @click.prevent="logIn()" flat value="logIn">
<span>LogIn</span>
<v-icon>whatshot</v-icon>
</v-btn>
<v-menu offset-y origin="center center" :nudge-bottom="10" transition="scale-transition">
<v-btn icon large flat slot="activator">
<v-avatar size="30px">
<img src="../assets/logo.png" alt="user-logo"/>
</v-avatar>
</v-btn>
<v-list class="pa-0">
<v-list-tile v-for="(item , index) in items"
:to="!item.href ? name: item.name : null"
:href="item.href"
@click.prevent="item.click"
ripple="ripple"
:disabled="item.disabled"
:target="item.target"
rel="noopener"
:key="index"
ref="myBtn"
>
<v-list-tile-action v-if="item.icon">
<v-icon> item.icon </v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title> item.title </v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-menu>
</v-bottom-nav>
</v-card>
<script>
import mapActions, mapState from 'vuex';
export default
name: 'home',
computed: mapState(['data' , 'loading']),
data()
return
bottomNav: 'LogIn',
items: [
icon: 'account_circle',
href: '#',
title: 'Profile',
click: ''
,
icon: 'settings',
href: '#',
title: 'Settings',
click: ''
,
icon: 'fullscreen_exit',
href: '#',
title: 'Logout',
click: () =>
this.logOut();
]
,
methods:
...mapActions(['logIn' , 'logOut']),
,
</script>
Actions.js
Im getting this error: Uncaught TypeError: Cannot set property 'data' of undefined this error is pointing to the mutation file in the UPDATE_DATA.
import GROUP_ID from '../config/env';
export const actions =
logIn(state , commit)
FB.login((res) =>
console.log(res);
if(res.status == "connected")
state.user.id = res.authResponse.userID;
state.user.accessToken = res.authResponse.accessToken;
console.log("user:%sntoken:%s" , state.user.id , state.user.accessToken);
FB.api('/me' , (res) =>
this.user.username = res.authResponse.name;
);
FB.api(`/$GROUP_ID/feed`,'GET', (res) =>
if(res && !res.error)
res['data'].forEach((data) =>
console.log("api connection => " , data);
commit('UPDATE_DATA' , data);
commit('IS_LOADING_DATA' , false);
);
);
,scope:'public_profile, email, groups_access_member_info');
,
logOut(state)
console.log(state.user.accessToken);
try
if(FB.getAccessToken() != null)
FB.logout(function(res)
console.log("User is logged out");
console.log(res);
);
else
console.log("User is not logged in");
catch(err)
console.log(err);
Mutations.js
export const mutations =
UPDATE_DATA(state , payload)
state.data = payload;
,
IS_LOADING_DATA(state , payload)
state.loading = payload;
javascript vue.js web-deployment vuex
1
Could you post your store code too, please?
– yuriy636
Nov 10 at 21:24
yea, let me added
– Chris Perez
Nov 10 at 21:30
Only visible issue seems arrow function use
– nara_l
Nov 10 at 21:37
This question is a little confusing with two different errors and no explanation about the second one. If they are independent issues, it would make more sense to make them separate posts.
– Jenna Pederson
Nov 10 at 21:41
Apologies .. I already solved the problem of the arrow function, but when the user does log-in, he shows me the following error "Uncaught TypeError: Can not set property 'data' of undefined"
– Chris Perez
Nov 10 at 21:48
|
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Regards,
I would like to know how I can access the logOut function that comes from mapActions,
What I do not understand is how it is possible, that with the logIn function when I refer to it, it works for me but with the function of logOut no.
Here is the error: Uncaught ReferenceError: logOut is not defined
Here I leave the code:
<template>
<div class="home">
<v-card height="200px" flat dark app>
<div class="headline text-xs-center pa-5">
Active: bottomNav
</div>
<v-bottom-nav :active.sync="bottomNav" :value="true" absolute color="transparent">
<v-btn color="teal" flat value="messages">
<span>Messages</span>
<v-icon>chat</v-icon>
</v-btn>
<v-btn color="teal" flat value="notifications">
<span>Notifications</span>
<v-icon>notifications</v-icon>
</v-btn>
<v-btn color="red" @click.prevent="logIn()" flat value="logIn">
<span>LogIn</span>
<v-icon>whatshot</v-icon>
</v-btn>
<v-menu offset-y origin="center center" :nudge-bottom="10" transition="scale-transition">
<v-btn icon large flat slot="activator">
<v-avatar size="30px">
<img src="../assets/logo.png" alt="user-logo"/>
</v-avatar>
</v-btn>
<v-list class="pa-0">
<v-list-tile v-for="(item , index) in items"
:to="!item.href ? name: item.name : null"
:href="item.href"
@click.prevent="item.click"
ripple="ripple"
:disabled="item.disabled"
:target="item.target"
rel="noopener"
:key="index"
ref="myBtn"
>
<v-list-tile-action v-if="item.icon">
<v-icon> item.icon </v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title> item.title </v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-menu>
</v-bottom-nav>
</v-card>
<script>
import mapActions, mapState from 'vuex';
export default
name: 'home',
computed: mapState(['data' , 'loading']),
data()
return
bottomNav: 'LogIn',
items: [
icon: 'account_circle',
href: '#',
title: 'Profile',
click: ''
,
icon: 'settings',
href: '#',
title: 'Settings',
click: ''
,
icon: 'fullscreen_exit',
href: '#',
title: 'Logout',
click: () =>
this.logOut();
]
,
methods:
...mapActions(['logIn' , 'logOut']),
,
</script>
Actions.js
Im getting this error: Uncaught TypeError: Cannot set property 'data' of undefined this error is pointing to the mutation file in the UPDATE_DATA.
import GROUP_ID from '../config/env';
export const actions =
logIn(state , commit)
FB.login((res) =>
console.log(res);
if(res.status == "connected")
state.user.id = res.authResponse.userID;
state.user.accessToken = res.authResponse.accessToken;
console.log("user:%sntoken:%s" , state.user.id , state.user.accessToken);
FB.api('/me' , (res) =>
this.user.username = res.authResponse.name;
);
FB.api(`/$GROUP_ID/feed`,'GET', (res) =>
if(res && !res.error)
res['data'].forEach((data) =>
console.log("api connection => " , data);
commit('UPDATE_DATA' , data);
commit('IS_LOADING_DATA' , false);
);
);
,scope:'public_profile, email, groups_access_member_info');
,
logOut(state)
console.log(state.user.accessToken);
try
if(FB.getAccessToken() != null)
FB.logout(function(res)
console.log("User is logged out");
console.log(res);
);
else
console.log("User is not logged in");
catch(err)
console.log(err);
Mutations.js
export const mutations =
UPDATE_DATA(state , payload)
state.data = payload;
,
IS_LOADING_DATA(state , payload)
state.loading = payload;
javascript vue.js web-deployment vuex
Regards,
I would like to know how I can access the logOut function that comes from mapActions,
What I do not understand is how it is possible, that with the logIn function when I refer to it, it works for me but with the function of logOut no.
Here is the error: Uncaught ReferenceError: logOut is not defined
Here I leave the code:
<template>
<div class="home">
<v-card height="200px" flat dark app>
<div class="headline text-xs-center pa-5">
Active: bottomNav
</div>
<v-bottom-nav :active.sync="bottomNav" :value="true" absolute color="transparent">
<v-btn color="teal" flat value="messages">
<span>Messages</span>
<v-icon>chat</v-icon>
</v-btn>
<v-btn color="teal" flat value="notifications">
<span>Notifications</span>
<v-icon>notifications</v-icon>
</v-btn>
<v-btn color="red" @click.prevent="logIn()" flat value="logIn">
<span>LogIn</span>
<v-icon>whatshot</v-icon>
</v-btn>
<v-menu offset-y origin="center center" :nudge-bottom="10" transition="scale-transition">
<v-btn icon large flat slot="activator">
<v-avatar size="30px">
<img src="../assets/logo.png" alt="user-logo"/>
</v-avatar>
</v-btn>
<v-list class="pa-0">
<v-list-tile v-for="(item , index) in items"
:to="!item.href ? name: item.name : null"
:href="item.href"
@click.prevent="item.click"
ripple="ripple"
:disabled="item.disabled"
:target="item.target"
rel="noopener"
:key="index"
ref="myBtn"
>
<v-list-tile-action v-if="item.icon">
<v-icon> item.icon </v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title> item.title </v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-menu>
</v-bottom-nav>
</v-card>
<script>
import mapActions, mapState from 'vuex';
export default
name: 'home',
computed: mapState(['data' , 'loading']),
data()
return
bottomNav: 'LogIn',
items: [
icon: 'account_circle',
href: '#',
title: 'Profile',
click: ''
,
icon: 'settings',
href: '#',
title: 'Settings',
click: ''
,
icon: 'fullscreen_exit',
href: '#',
title: 'Logout',
click: () =>
this.logOut();
]
,
methods:
...mapActions(['logIn' , 'logOut']),
,
</script>
Actions.js
Im getting this error: Uncaught TypeError: Cannot set property 'data' of undefined this error is pointing to the mutation file in the UPDATE_DATA.
import GROUP_ID from '../config/env';
export const actions =
logIn(state , commit)
FB.login((res) =>
console.log(res);
if(res.status == "connected")
state.user.id = res.authResponse.userID;
state.user.accessToken = res.authResponse.accessToken;
console.log("user:%sntoken:%s" , state.user.id , state.user.accessToken);
FB.api('/me' , (res) =>
this.user.username = res.authResponse.name;
);
FB.api(`/$GROUP_ID/feed`,'GET', (res) =>
if(res && !res.error)
res['data'].forEach((data) =>
console.log("api connection => " , data);
commit('UPDATE_DATA' , data);
commit('IS_LOADING_DATA' , false);
);
);
,scope:'public_profile, email, groups_access_member_info');
,
logOut(state)
console.log(state.user.accessToken);
try
if(FB.getAccessToken() != null)
FB.logout(function(res)
console.log("User is logged out");
console.log(res);
);
else
console.log("User is not logged in");
catch(err)
console.log(err);
Mutations.js
export const mutations =
UPDATE_DATA(state , payload)
state.data = payload;
,
IS_LOADING_DATA(state , payload)
state.loading = payload;
javascript vue.js web-deployment vuex
javascript vue.js web-deployment vuex
edited Nov 10 at 21:35
asked Nov 10 at 21:05
Chris Perez
215
215
1
Could you post your store code too, please?
– yuriy636
Nov 10 at 21:24
yea, let me added
– Chris Perez
Nov 10 at 21:30
Only visible issue seems arrow function use
– nara_l
Nov 10 at 21:37
This question is a little confusing with two different errors and no explanation about the second one. If they are independent issues, it would make more sense to make them separate posts.
– Jenna Pederson
Nov 10 at 21:41
Apologies .. I already solved the problem of the arrow function, but when the user does log-in, he shows me the following error "Uncaught TypeError: Can not set property 'data' of undefined"
– Chris Perez
Nov 10 at 21:48
|
show 2 more comments
1
Could you post your store code too, please?
– yuriy636
Nov 10 at 21:24
yea, let me added
– Chris Perez
Nov 10 at 21:30
Only visible issue seems arrow function use
– nara_l
Nov 10 at 21:37
This question is a little confusing with two different errors and no explanation about the second one. If they are independent issues, it would make more sense to make them separate posts.
– Jenna Pederson
Nov 10 at 21:41
Apologies .. I already solved the problem of the arrow function, but when the user does log-in, he shows me the following error "Uncaught TypeError: Can not set property 'data' of undefined"
– Chris Perez
Nov 10 at 21:48
1
1
Could you post your store code too, please?
– yuriy636
Nov 10 at 21:24
Could you post your store code too, please?
– yuriy636
Nov 10 at 21:24
yea, let me added
– Chris Perez
Nov 10 at 21:30
yea, let me added
– Chris Perez
Nov 10 at 21:30
Only visible issue seems arrow function use
– nara_l
Nov 10 at 21:37
Only visible issue seems arrow function use
– nara_l
Nov 10 at 21:37
This question is a little confusing with two different errors and no explanation about the second one. If they are independent issues, it would make more sense to make them separate posts.
– Jenna Pederson
Nov 10 at 21:41
This question is a little confusing with two different errors and no explanation about the second one. If they are independent issues, it would make more sense to make them separate posts.
– Jenna Pederson
Nov 10 at 21:41
Apologies .. I already solved the problem of the arrow function, but when the user does log-in, he shows me the following error "Uncaught TypeError: Can not set property 'data' of undefined"
– Chris Perez
Nov 10 at 21:48
Apologies .. I already solved the problem of the arrow function, but when the user does log-in, he shows me the following error "Uncaught TypeError: Can not set property 'data' of undefined"
– Chris Perez
Nov 10 at 21:48
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
If you change to use a non-arrow function in your data click
, you'll have access to the correct Vue instance. By using an arrow function, this
is not the Vue instance you're expecting and this.logOut
will be undefined.
The only problem I have comes from the file mutations.js especially from UPDATE_DATA, Uncaught TypeError: Can not set property 'data' of undefined
– Chris Perez
Nov 10 at 21:44
1
@ChrisPerez may be open a different question
– nara_l
Nov 10 at 21:59
@ChrisPerez It might be worth accepting this answer (since it solves the original problem as described in both the post and the title) and opening a new one with a better title and description.
– Jenna Pederson
Nov 11 at 21:15
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If you change to use a non-arrow function in your data click
, you'll have access to the correct Vue instance. By using an arrow function, this
is not the Vue instance you're expecting and this.logOut
will be undefined.
The only problem I have comes from the file mutations.js especially from UPDATE_DATA, Uncaught TypeError: Can not set property 'data' of undefined
– Chris Perez
Nov 10 at 21:44
1
@ChrisPerez may be open a different question
– nara_l
Nov 10 at 21:59
@ChrisPerez It might be worth accepting this answer (since it solves the original problem as described in both the post and the title) and opening a new one with a better title and description.
– Jenna Pederson
Nov 11 at 21:15
add a comment |
up vote
0
down vote
If you change to use a non-arrow function in your data click
, you'll have access to the correct Vue instance. By using an arrow function, this
is not the Vue instance you're expecting and this.logOut
will be undefined.
The only problem I have comes from the file mutations.js especially from UPDATE_DATA, Uncaught TypeError: Can not set property 'data' of undefined
– Chris Perez
Nov 10 at 21:44
1
@ChrisPerez may be open a different question
– nara_l
Nov 10 at 21:59
@ChrisPerez It might be worth accepting this answer (since it solves the original problem as described in both the post and the title) and opening a new one with a better title and description.
– Jenna Pederson
Nov 11 at 21:15
add a comment |
up vote
0
down vote
up vote
0
down vote
If you change to use a non-arrow function in your data click
, you'll have access to the correct Vue instance. By using an arrow function, this
is not the Vue instance you're expecting and this.logOut
will be undefined.
If you change to use a non-arrow function in your data click
, you'll have access to the correct Vue instance. By using an arrow function, this
is not the Vue instance you're expecting and this.logOut
will be undefined.
answered Nov 10 at 21:36
Jenna Pederson
2,79811116
2,79811116
The only problem I have comes from the file mutations.js especially from UPDATE_DATA, Uncaught TypeError: Can not set property 'data' of undefined
– Chris Perez
Nov 10 at 21:44
1
@ChrisPerez may be open a different question
– nara_l
Nov 10 at 21:59
@ChrisPerez It might be worth accepting this answer (since it solves the original problem as described in both the post and the title) and opening a new one with a better title and description.
– Jenna Pederson
Nov 11 at 21:15
add a comment |
The only problem I have comes from the file mutations.js especially from UPDATE_DATA, Uncaught TypeError: Can not set property 'data' of undefined
– Chris Perez
Nov 10 at 21:44
1
@ChrisPerez may be open a different question
– nara_l
Nov 10 at 21:59
@ChrisPerez It might be worth accepting this answer (since it solves the original problem as described in both the post and the title) and opening a new one with a better title and description.
– Jenna Pederson
Nov 11 at 21:15
The only problem I have comes from the file mutations.js especially from UPDATE_DATA, Uncaught TypeError: Can not set property 'data' of undefined
– Chris Perez
Nov 10 at 21:44
The only problem I have comes from the file mutations.js especially from UPDATE_DATA, Uncaught TypeError: Can not set property 'data' of undefined
– Chris Perez
Nov 10 at 21:44
1
1
@ChrisPerez may be open a different question
– nara_l
Nov 10 at 21:59
@ChrisPerez may be open a different question
– nara_l
Nov 10 at 21:59
@ChrisPerez It might be worth accepting this answer (since it solves the original problem as described in both the post and the title) and opening a new one with a better title and description.
– Jenna Pederson
Nov 11 at 21:15
@ChrisPerez It might be worth accepting this answer (since it solves the original problem as described in both the post and the title) and opening a new one with a better title and description.
– Jenna Pederson
Nov 11 at 21:15
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243396%2fhow-to-access-a-mapaction-method-using-vuejs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Could you post your store code too, please?
– yuriy636
Nov 10 at 21:24
yea, let me added
– Chris Perez
Nov 10 at 21:30
Only visible issue seems arrow function use
– nara_l
Nov 10 at 21:37
This question is a little confusing with two different errors and no explanation about the second one. If they are independent issues, it would make more sense to make them separate posts.
– Jenna Pederson
Nov 10 at 21:41
Apologies .. I already solved the problem of the arrow function, but when the user does log-in, he shows me the following error "Uncaught TypeError: Can not set property 'data' of undefined"
– Chris Perez
Nov 10 at 21:48