Question has been updated
I tried using a store from Pinia and a web component created with Vue.js but I got this error in the console:
[Vue warn]: Injection "Symbol(pinia)" not found at
I have a very simple example.
import { defineCustomElement } from 'vue' import HelloWorld from './components/HelloWorld.ce.vue' const ExampleElement = defineCustomElement(HelloWorld) customElements.define('hello-world', ExampleElement)
import { defineStore, createPinia, setActivePinia } from "pinia"; setActivePinia(createPinia()); export const useCounterStore = defineStore('counter', { state: () => ({ counter: 0, }), actions: { increment() { this.counter++; }, }, });
<script setup lang="ts"> import { ref } from 'vue' import { useCounterStore } from '../store.ts' defineProps<{ msg: string }>() const store = useCounterStore() </script> <template> <h1>{{ msg }}</h1> <div class="card"> <button type="button" @click="store.increment()">count is {{ store.counter }}</button> </div> </template>
After creating pinia in main.js, you will recreate pinia in the store. Remove these lines from your store: