导入到typescript pinia vue时键入商店

yvfmudvl  于 2023-02-24  发布在  Vue.js
关注(0)|答案(1)|浏览(121)

导入到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
    }
  }
})
elcex8rz

elcex8rz1#

您只需要在组件对象周围使用defineComponent() Package 器就可以拥有Typescript类型:

// Will correctly type your component data, methods etc.
export default defineComponent({
  setup() {}
})

相关问题