note.js
import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useNoteStore = defineStore('note', () => {
cosnt noteList = ref([
{
title: '标题',
desc: '详情内容'
}
]),
return {
noteList
}
})
user.js
import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useuserStore = defineStore('user', () => {
cosnt user = ref(
{
name: 'bob',
phone: 15729837802,
emial: '2966211270@qq.com'
}
),
return {
user
}
})
import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useuserStore = defineStore('user', () => {
cosnt user = ref(
{
name: 'bob',
phone: 15729837802,
emial: '2966211270@qq.com'
}
),
function isLoggedIn() {
return user.value != null
}
return {
user,
isLoggedIn
}
})
note.js
中访问其他 store
import { ref } from 'vue'
import { defineStore } from 'pinia'
import { useUserStore } from './user.js'
export const useNoteStore = defineStore('note', () => {
cosnt noteList = ref([
{
title: '标题',
desc: '详情内容'
}
]),
const userStore = useUserStore()
function addNote() {
if(userStore.isLoggedIn) {
setTimeout(() => {
noteList.push({
title: '标题x'
desc: '详情内容x'
})
}, 2000)
}
}
return {
noteList
}
})