0

I started vuex study and i have an error in Vue.js/Vuex-store: 6:1 error Prefer default export import/prefer-default-export; The error telling me that i have to change export const store to export default and i don't want it

I can't fix and help please;

// Vuex store
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export const store = new Vuex.Store({
  state: {
    count: 0,
  },
  getters: {
    increment: (state) => {
      state.count += 1;
    },
  },
});


// main.js
import Vue from 'vue';
import App from './App.vue';
import { store } from './Vuex-store/store.js';

new Vue({
  render: (h) => h(App),
  store,
}).$mount('#app');
<template>
  <div>
    {{ this.$store.state.count }}
    <button @click="increment">increment</button>
  </div>
</template>

<script>
export default {
  data() {
    return {

    };
  },
  methods: {
    increment() {
      this.$store.getters.increment;
    },
  },
};
</script>

2 Answers 2

1

this is just an eslint rule. It wants you to do a default export instead of export const:

Export it like this:

export default store

Then, instead of importing like

import { store } from './Vuex-store/store.js';

do just

import store from './Vuex-store/store.js';
Sign up to request clarification or add additional context in comments.

4 Comments

it's don't working again error: 6:16 error 'store' is not defined no-undef
could you show me the code somewhere? Which line is the throwing the error in which of the two files?
export default store
first set const store = new Vue.Store({}), then export this store variable using export default store
0

Try it

<template>
  <div>
    {{ count }}
    <button @click="increment">increment</button>
  </div>
</template>

<script>
export default {
  data() {
    return {

    };
  },
  computed: {
    count() {
      return this.$store.state.count;
    }
  },
  methods: {
    increment() {
      this.$store.getters.increment;
    },
  },
};
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.