导入到typescript pinia vue时如何键入商店。是否需要键入?
// Component
<p>{{ storeForm.firstName }}</p> // getting an error "Property 'storeForm' does not exist on type"
// Store
import { defineStore } from 'pinia'
export const useForm = defineStore('login',{
state: () => ({
firstName: <string>'',
lastName: <string>''
}),
getters: {
},
actions: {
login(data: any) {
this.firstName = data.firstName
this.lastName = data.lastName
}
}
})
1条答案
按热度按时间elcex8rz1#
您只需要在组件对象周围使用
defineComponent()
Package 器就可以拥有Typescript类型: