💼recommended
, ✅ recommended-flat
. This rule warns in the following configs: 🌐 all
, 🌐 all-flat
.
When stores are cross used, whichever store gets its use... called first will exists as a placeholder in the other store until its own setup function returns. That's why storeToRefs() do not work there and should be avoided altogether with cross used stores.
❌ Examples of incorrect code for this rule:
import { useUserStore } from './user'
export const useCartStore = defineStore('cart', () => {
const { user } = storeToRefs(useUserStore())
const list = ref([])
const summary = computed(() => {
return `Hi ${user.name}, you have ${list.value.length} items in your cart. It costs ${price.value}.`
})
function purchase() {
return apiPurchase(user.id, this.list)
}
return { summary, purchase }
})
✅ Examples of correct code for this rule:
import { useUserStore } from './user'
export const useCartStore = defineStore('cart', () => {
const { user } = useUserStore()
const list = ref([])
const summary = computed(() => {
return `Hi ${user.name}, you have ${list.value.length} items in your cart. It costs ${price.value}.`
})
function purchase() {
return apiPurchase(user.id, this.list)
}
return { summary, purchase }
})