- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
无法通过 vuex store 和 vue.js 找出这个错误:
这是 webpack-cli 的东西吗?还是我做的不对?感谢您的帮助!
Module parse failed: /Users/me/sites/vue/src/components/SectionView.Vue Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <template>
| <ul class="listing">
| <li v-for="item in $store.state.items">
@ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/PanelBody.vue 3:0-56
@ ./src/components/PanelBody.vue
@ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Panel.vue
@ ./src/components/Panel.vue
@ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Accordion.vue
@ ./src/components/Accordion.vue
@ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Sidebar.vue
@ ./src/components/Sidebar.vue
@ ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Body.vue
@ ./src/components/Body.vue
@ ./src/router/index.js
@ ./src/main.js
@ multi ./build/dev-client ./src/main.js
我的 SectionView.vue 文件:
<template>
<ul class="listing">
<li v-for="item in $store.state.items">
<router-link :to="{ name: 'item', params: { id: item.id }}">
<img :src="item.image" />
<br>{{ item.name }}
</router-link>
</li>
</ul>
</template>
<script>
import Item from '../components/Item',
export default {
name: 'SectionView',
components: {
'item': Item
},
created () {
this.$store.dispatch('fetch')
}
},
}
</script>
我的 Item.vue:
<template>
<div id="section-view">
<div class="item-view">
<router-link class="back-listing" :to="{name: 'section'}">U+0003C</router-link>
<div class="item">
<h1>{{ item.name }}</h1>
</div>
</div>
</template>
<script>
export default {
name: 'item',
computed: {
item: function () {
return this.$store.state.items.find(item => item.id === this.$route.params.id)
}
},
created () {
this.$store.dispatch('open', this.$route.params.id)
}
}
</script>
我的商店在 src/store/index.js 中:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const db = [
{ id: 'a', name: 'Item #1', image: 'http://lorempicsum.com/simpsons/350/200/1' },
{ id: 'b', name: 'Item #2', image: 'http://lorempicsum.com/simpsons/350/200/2' },
{ id: 'c', name: 'Item #3', image: 'http://lorempicsum.com/simpsons/350/200/3' }
]
const store = new Vuex.Store({
state: {
items: [],
opened: {}
},
actions: {
fetch: function ({commit, state}, payload) {
commit('SET_LIST', db) // Just clone the array
},
open: function ({commit, state}, payload) {
// look for item in local state
var localItem = state.items.find(item => payload === item.id)
if (!localItem) {
new Promise(function (resolve, reject) {
return db.find(item => payload === item.id)
})
.then(result => {
commit('ADD_ITEM', result)
})
}
}
},
mutations: {
SET_LIST: function (state, payload) {
Vue.set(state, 'items', payload)
},
ADD_ITEM: function (state, playload) {
state.items.push()
}
}
})
console.log('State', store)
export default store
我的 main.js 调用商店:
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import store from './store'
import App from './App'
import router from './router'
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
store,
router,
template: '<App/>',
components: { App }
})
最佳答案
就像@MateenRay 所说的“.Vue”而不是“.vue”确实可能是问题所在。
这都是关于您的操作系统。
在 Windows 上,“FILE.txt”和“file.txt”是相同的。因此,当调用您的 vue 文件时,大小写无关紧要。
但对于 linux,“FILE.txt”和“file.txt”是两个独立的文件!因此,调用您的“.Vue”文件与调用“.vue”文件不同。
记住这一点很重要,因为在我的项目中我们在 windows 上并没有注意这一点。接下来,我们将所有文件名从“file”更改为“File”。接下来,我们不得不在 Linux 机器上交付它,但由于找不到某些文件,所以没有任何工作......我们中的一些人仍在导入如下文件:
import file from ...
而不是 import File from ...
它在 windows 上工作,但在 linux 上不工作。
关于vue.js - 模块解析失败 : Unexpected token (1:0) vue. js vuex store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44745079/
我刚刚开始使用 Vuex,但遇到了问题(这可能是我的一些无能为力的语法错误)。我有一个用户喜欢 like_items 并且有一个网络调用,它与一个项目不同。 mutations: { SET_TOGG
我刚开始在这里学习 Vuex。到目前为止,我一直将共享数据存储在 store.js 中。文件和导入store在每个模块中,但这越来越烦人,我担心会发生变异。 我正在努力解决的是如何使用 Vuex 从
我正在创建一个使用 Fabric.js 来管理 Canvas 的 Vue 应用程序。 我想使用 Vuex 管理 Canvas 状态。为此,我将 fabric canvas 实例设置为 vuex 状态变
我正在构建一个 Nuxt 应用程序,我正在从我在本地主机上运行的节点后端获取一些数据。 我有一个插件 getApps.js export default ({ store }) => { st
我想安装 Vuex 但出现错误。 // error npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree
我使用 vuex-persistedstate 包( https://github.com/robinvdvleuten/vuex-persistedstate )在浏览器上保持数据状态。 我使用 A
假设我有一个简单的 Vuex 状态来保存食谱: const state = { recipe: { id: '', name: "", ingr
目前,我有一个具有 2 个状态属性的商店 - 版本和冠军 + 2 个发出 GET 请求然后提交到状态的操作。第二个 GET 请求 URL 需要包含我从第一个 GET 请求获取的版本,如下所示: axi
我有一个基于 Vue 和 Vuex 的小应用程序。它只是一个包含类似项目的表格 {{ item.name }} Edit Items 数组是使用 getter 从
我有一个 Vuex getter,我从应用程序中的各个组件调用它。但是,我发现在调用 getter 之前需要稍微复杂一些的逻辑,所以我使用了 Vuex Action。如何使用操作中的参数调用 gett
为什么会出现此错误: Error [vuex] Do not mutate vuex store state outside mutation handlers. 这是什么意思? 当我尝试输入编辑输入
在 Nuxt 文档(here)中,它说“您可以选择将模块文件分解为单独的文件:state.js、actions.js、mutations.js 和 getters.js。” 我似乎找不到任何示例来说明
我正在使用 TypeScript 构建一个简单的 vue 项目。我在我的 vue 项目中编写了 vuex 商店,该商店有一个名为“计算”的子模块。但是一旦创建了包含子模块的主存储,就会发生奇怪的错误(
我完全熟悉 Vuex,但我对 Vue 组合 API 一无所知。这到底是怎么回事,它和Vuex有什么区别?它涵盖了 Vuex 中的哪些差距,以及何时何地使用它们更好? 感谢您的帮助。 最佳答案 首先,
简短的问题:是否可以通过 Nuxt Auth 模块手动更新 Vuex 中的用户数据? 为什么我有这个问题:我的问题是这个。我在用户文档中的 MongoDB 中保存了一些 Likes/Follows。我
尝试将带有 vuex-module-decorators 的存储模块加载到初始化程序中时出现此错误: vuex.esm.js?2f62:261 Uncaught TypeError: Cannot r
我有一个 VueX 商店,有两个模块,user.js 和merchant.js,顶层是index.js。 user.js 中的 getter 是: 重构 const getters = { s
我在我的代码库中偶然发现了这个错误,并试图看看是否有人可以修复它。 以下是我的 listings/actions.js export const fetchFeaturedListings = ({
我正在尝试将 Vuex 与 Vue 3 一起使用。这是我在 main.js 中的代码: import { createApp } from 'vue'; import App from './App.
我在我的代码库中偶然发现了这个错误,并试图看看是否有人可以修复它。 以下是我的 listings/actions.js export const fetchFeaturedListings = ({
我是一名优秀的程序员,十分优秀!