state新建文件index.js
import { defineStore } from 'pinia'
import { reactive } from 'vue'
export const usellStore = defineStore('ll', () => {
const user = reactive({
username: "陈明祥",
password: "520",
sex: "男",
monry: 100000
})
function UpdateUser() {
user.username = "流浪"
}
return { user, UpdateUser }
})
使用步骤
<template>
<div>
<h1>hello</h1>
</div>
</template>
<script setup lang="ts">
import { usellStore } from '@/state/index'
const userll = usellStore()
userll.$patch({
user: {
username: "XXX"
}
})
console.log(userll.user.username)
userll.UpdateUser()
</script>
<style scoped></style>