parent.vue
<template>
{{ CommonTest }}
</template>
<script setup>
import { getCurrentInstance } from 'vue';
// 获取 当前组件示例的全部属性
const { proxy } = getCurrentInstance();
// 但是全局的 $pinia 如果从未被调用过,是不会被创建的。
// 所以不推荐这种访问模式
// 从 pinia 实例读取过来的数据 是已经进行过双向绑定的数据
const CommonTest = proxy.$pinia.state.value.CommonTest;
</script>
<style lang="less" scoped>
</style>
store.js
import { defineStore } from 'pinia'
import { store } from '@STORE';
export const CommonTestStore = defineStore('CommonTest', {
state: () => {
return {
value: 'test'
}
},
getters: {
},
actions: {
}
})
export function GetCommonTestStore() {
return CommonTestStore(store);
}