引入pinia:
在main.js中对pinia进行引入,使用和导出
import * as Pinia from 'pinia'; // 引入pinia
app.use(Pinia.createPinia()); // 使用pinia

在项目根目录下创建一个stores文件夹,里面创建一个counter.js文件

我们在counter.js中定义两个变量和一个函数,并进行导出

在需要使用的地方引入pinia,并使用函数接受导出的对象
import {useCounterStore} from "@/stores/counter.js"; // 导入pinia
let counterStore = useCounterStore(); // 获取导出对象
我们可以直接当做正常的变量去使用