Vuejs 3 Pinia not working, Cannot read properties of undefined (reading 'startsWith')
Asked Answered
M

2

7

I try to use Pinia but it never works. Doesn't matter if I install it with Vite at the start of the project or if I add it later. It always write the same error. This is an example from my last project.

enter image description here

This is my main.js

import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
import draggable from "vuedraggable";

const app = createApp(App);

app.use(createPinia());
app.component('draggable', draggable);
app.mount("#app");

This is start of my App.vue

<script setup>
import { ref } from "vue";
import draggable from "vuedraggable";
import {useCounterStore} from "./stores/counter";
const storeCounter = useCounterStore();

The error appears when I enter

const storeCounter = useCounterStore();
Menswear answered 23/5, 2022 at 20:39 Comment(1)
Please, provide stackoverflow.com/help/mcve . What is ./stores/counter ?Stubstad
M
7

I did tests in Firefox instead of Chrome and the explanation was much better. It told me I was missing "id: counter" in my counter.js in "export const counter".

enter image description here

Menswear answered 24/5, 2022 at 11:16 Comment(0)
F
0

It is refering to the ref that is used when creating the store..

refer to the below store

import { defineStore } from 'pinia'

import { io } from 'socket.io-client'

const client = io('http://localhost:3000')
export const useMessageStore = defineStore('messageStore',{
    state: () => ({
        client: client,
        username: null,
        connected: false,
        users: 0,
        messages: [],
    }),

    actions: {
        getMessages() {
            this.client.emit('getMessages')
        },
    },
})

export const useMessageStore = defineStore('messageStore',{

the 'messageStore' part is what they mean when they say the Id...

Firing answered 27/3, 2023 at 16:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.