1.全局注册方法
import store from '@/store'
app.config.globalProperties.$store = store();
2.pinia的使用
注意:pinia不要使用全局注册方法,会导致在当前页面修改数据失败 ①首先在main.ts中注册
import { createPinia } from "pinia";
app.use(createPinia())
②store/index.ts中
import { defineStore } from 'pinia'
export const exportStore = defineStore({
id: 'shi',
state: () => {
return {
homeAnchor: 9999,
solutionAnchor: 9999,
successCaseAnchor: 9999,
aboutUsAnchor: 9999,
}
},
getters: {},
actions: {}
})
③其他组件就可以使用了
import { exportStore } from "@/store";
const pinia = exportStore()
然后通过pinia.solutionAnchor就可以取到值了