nikoloz gabidzashvili
nikoloz gabidzashvili

Reputation: 11

Vue.js error 6:1 error Prefer default export import/prefer-default-export

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>

Upvotes: 0

Views: 157

Answers (2)

grovskiy
grovskiy

Reputation: 788

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>

Upvotes: 0

Abbas
Abbas

Reputation: 1255

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';

Upvotes: 1

Related Questions