VueJs 3 - Vuex: Uncaught TypeError: storan bukan fungsi
P粉824889650
P粉824889650 2024-03-25 21:26:36
0
2
438

Saya sedang belajar Vuejs dan dalam projek saya sejak saya cuba menggunakan kedai (VUEX) saya mendapat beberapa amaran dan tiada apa yang ditunjukkan

Jadi saya ada:

├── index.html
└── src
     ├── views
        └── Feed.vue      
     └──store
       └── index.ts
     ├── App.vue
     ├── main.ts

Perkara utama saya ialah:

// initialisation des éléments pours VUE
import { createApp } from "vue";
import App from "./App.vue";
import "./registerServiceWorker";
import router from "./router";
import store from "./store";
import axios from 'axios'
import VueAxios from 'vue-axios'


// initialisation des imports pour Font Awesome
import { library } from "@fortawesome/fontawesome-svg-core";
import { faUserSecret } from "@fortawesome/free-solid-svg-icons";
import {
  faSpinner,
  faPaperPlane,
  faHandPeace,
  faSignOutAlt,
  faShieldAlt,
  faUserPlus,
  faImage,
  faEdit,
  faUsersCog,
  faTools,
  faRss,
  faTimesCircle,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";

// initialisation des imports pour Bootstrap
import "bootstrap/dist/css/bootstrap.min.css";
import "bootstrap";
import "bootstrap/dist/js/bootstrap.js";

// intégration des icones font awesome à la librairy
library.add(faUserSecret);
library.add(faSpinner);
library.add(faPaperPlane);
library.add(faHandPeace);
library.add(faSignOutAlt);
library.add(faShieldAlt);
library.add(faUserPlus);
library.add(faImage);
library.add(faEdit);
library.add(faEdit);
library.add(faUsersCog);
library.add(faTools);
library.add(faRss);
library.add(faTimesCircle);


// Création de l'app
const app = createApp(App);
  app.use(store);
  app.use(router);
  app.use(VueAxios, axios);
  app.provide('axios', app.config.globalProperties.axios) ;
  app.component("font-awesome-icon", FontAwesomeIcon);
  app.mount("#app");

my./store/index.ts

// Imports 
import { createApp } from 'vue'
import { createStore } from 'vuex'
import axios from 'axios';


//Create Store :

export const store = createStore({

  // Define state
  state () {
    return{
      feedList: []
    }
  },

  // Define Actions
  actions: {
    getPosts( { commit } ) {
      axios.get('http://localhost:3001/api/feed')
          .then(feedList => {
            commit('setFeedList', feedList)
      })
    }
  },

  // Define mutations
  mutations: {
    setFeedList(state:any, feedList:any) {
      state.data = feedList
    }
  }, 

})

My ./views/Feed.vue:

<template>
  <div id="Feed">
    <div id="profil" class="col-12 col-md-3">
      <Cartridge />
    </div>
    <div id="feedcontent" class="col-12 col-md-9">
      <SendPost />
      <div id="testlist" v-for="thePost in feedList" :key="thePost">
        {{ thePost }}
    </div>
  </div>
</template>

<script lang="ts">
import Cartridge from '@/components/Cartridge.vue';
import SendPost from '@/components/SendPost.vue';
import { computed } from 'vue'
import { useStore } from 'vuex'

export default {
  name: 'Feed',
  components: {
    Cartridge,
    SendPost
  },

  setup () {
    const store = useStore();

    const feedList = computed(() => store.state.data.feedList);
    console.log("feedList > " + feedList.value);
    return {
      feedList
    }
  },
}
</script>

<style lang="scss">
@import "../scss/variables.scss";

#profil {
  position: fixed;
  margin: 0;
  height: 100%;
}

#feedcontent {
  position: fixed;
  height: 100%;
  right: 0;
  background-color: $groupo-colorLight1;
  overflow-y: scroll;

  ::-webkit-scrollbar {
    width: 8px;
    color: $groupo-color1;
  }

  ::-webkit-scrollbar-track {
    background: $groupo-colorLight2;
    width: 20px;
    -webkit-box-shadow: inset 0 0 6px rgba($groupo-color4, 0.3);
  }

  ::-webkit-scrollbar-thumb {
    background: $groupo-color4;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: $groupo-color1;
  }
}
</style>

Nampaknya saya tidak faham sesuatu dalam Vuex, tetapi saya tidak tahu apa. Bolehkah anda memberitahu saya apa yang salah? (Saya harap ia tidak banyak:)) / Bolehkah sesiapa membantu saya? tolonglah.

Terima kasih

P粉824889650
P粉824889650

membalas semua(2)
P粉463291248

Nampaknya anda mendapat ralat daripada talian dalam ./store/index.ts di mana anda cuba menggunakan panggilan fungsi kepada eksport yang terhasil bagi contoh kedai pada baris ini:

export 默认存储();

Instance kedai memang bukan fungsi, anda mengimport hasilnya ke dalam main.ts . Cuba eksport hanya contoh kedai:

export默认商店

Mungkin anda tidak memerlukan baris selepas:

const app = createApp({})
app.use(store)
P粉267791326

Bukan sekadar jawapan yang sangat bagus daripada @Lucas David Ferrero, saya terlupa satu perkara dalam feed.vue saya...: kedai sudah dipasang! Jadi fail saya sekarang ialah:



sssccc

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan