我第一次使用vue.js,遇到了我研究过的问题,但还没有深入。到目前为止,我已经找到了建议:
Uncaught TypeError: this.$store.commit is not a function
https://forum.vuejs.org/t/vuex-this-store-commit-is-not-a-function/31001
我有这家商店:
import Vue from 'vue';
import Vuex from 'vuex';
const state = {
loggedIn: false
}
const mutations = {
truthify: state => state.loggedIn = true
}
const getters = {
loggedIn: state = state.loggedIn
}
const store = new Vuex.Store {
state,
getters,
mutations,
actions
}
export default store;
指向此组件:
<template>
<div class="login">
<div id="loginMain">
<form>
<label for="username">Username:</label>
<input type="text" id="username"></input>
<label for="password">Password:</label>
<input type="text" id="password"></input>
{{ loggedIn }}
<input type="button" value="submit" id="post-form" @click="testLogin"/>
</form>
</div>
</div>
</template>
<script>
import { mapState, vuex } from 'vuex'
import store from '@/store/'
export default {
name: 'Login',
data: function() {
return {
loggedIn: ''
}
},
computed: {
returnMessage: function() {
return this.$store.state.loggedIn
}
},
methods: {
testLogin(){
console.log('foo');
this.$store.commit('truthify');
}
},
store: store,
}
</script>
我不确定是什么问题。