重复此操作。$ store.commit不是功能问题

时间:2018-06-22 19:53:01

标签: javascript vue.js vuex

我第一次使用vue.js,遇到了我研究过的问题,但还没有深入。到目前为止,我已经找到了建议:

https://laracasts.com/discuss/channels/vue/vuex-anybody-typeerror-thisstorecommit-is-not-a-function?page=1

Uncaught TypeError: this.$store.commit is not a function

https://forum.vuejs.org/t/vuex-this-store-commit-is-not-a-function/31001

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=7&cad=rja&uact=8&ved=0ahUKEwjk_I-AhejbAhWPv1MKHRjMAyEQFghtMAY&url=https%3A%2F%2Falligator.io%2Fvuejs%2Fintro-to-vuex%2F&usg=AOvVaw2Pimf2n5yvOU5NpRsaCfCz

我有这家商店:

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>

我不确定是什么问题。

0 个答案:

没有答案