Having trouble using the commit
method as described here. I suspect it's because I'm using export default new Vuex.Store
instead of
export const store = new Vuex.Store
. However, when I make this change, I encounter an issue similar to the one in this post.
You can find my JS file where I'm utilizing Vuex and trying to use commit
here:
actions: {
signUserIn(payload) {
payload.password;
var params = new URLSearchParams();
params.append("grant_type", "password");
params.append("username", "admin");
params.append("password", "adminPassword");
axios({
method: "post",
url: "http://localhost:8090/oauth/token",
auth: { username: "my-trusted-client", password: "secret" },
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=utf-8"
},
data: params
}).then(function(response) {
const user = {
login: payload.username
};
localStorage.setItem("access_token", response.data.access_token);
this.commit("setUser", user);
});
}
},
When attempting to run this code and call signUserIn
, I receive the following error in the console:
TypeError: Cannot read property 'commmit' of undefined
I'm not sure what keywords to search for to resolve this issue.