未捕获的类型错误:this.$store.commit 不是函数 [英] Uncaught TypeError: this.$store.commit is not a function

查看:43
本文介绍了未捕获的类型错误:this.$store.commit 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 vue 方法想要将数据提交到 vuex 突变,出于某种原因,我不断收到 Uncaught TypeError: this.$store.commit is not a function

当我单击列表项并调用该函数时会触发错误.

<小时>

sample.vue

<li class="tabs-title" v-for="item in filtersItems" v-on:click="upComponents" :key="item.initials" >导出默认{数据() {返回 {搜索:空,};},计算:{过滤项目(){const 硬币 = this.$store.state.coin.coin;if (!this.search) 返回硬币;const searchValue = this.search.toLowerCase();const 过滤器 = 硬币 =>coin.initials.toLowerCase().includes(searchValue) ||coin.name.toLowerCase().includes(searchValue);返回硬币.过滤器(过滤器);},},方法: {upComponents(项目){this.$store.commit('updatedComp', item);},},安装(){this.tabs = new Foundation.Tabs($('#exchange-tabs'), {匹配高度:假,});},销毁(){this.tabs.destroy();},};

这是我在其中声明突变的 store.js 文件.

从'vue'导入Vue;从 'vuex' 导入 Vuex;从'../data/system.json'导入硬币;Vue.use(Vuex);导出默认{状态: {硬币,selectedCoin: 'jgjhg',},突变:{更新的Comp(状态,新ID){state.selectedCoin.push(newID);},},吸气剂:{硬币:状态 =>状态币,},};

main.js,这是我声明 Vue 应用程序的地方

从'jquery'导入jQuery;从'vue'导入Vue;从'./App'导入应用程序;从'./router'导入路由器;从 './store/store' 导入商店;window.jQuery = jQuery;窗口.$ = jQuery;要求('运动-ui');要求('什么输入');require('基础站点');新的 Vue({el: '#app',店铺,路由器,模板:'<App/>',组件:{应用},});

这是我正在处理的页面,我在其中加载了所有组件: