Home > Software engineering >  How to assign an interface to a reactive() object Vuejs 3
How to assign an interface to a reactive() object Vuejs 3

Time:07-09

How to assign an interface to a reactive() object Vuejs 3

Interface

export interface ProdutoInterface {
  codigo: number
  nome: string
}

Component

const dadosProduto = reactive()

I can't get it to work. Would anyone know how to help me.

thank you very much for your attention

CodePudding user response:

You can add interface like this way

1. need to initialize object insize reactive

const dadosProduto = reactive<ProdutoInterface>({
 codigo: 1,
 nome: 'some string'
})

or

const dadosProduto: ProdutoInterface = reactive({
 codigo: 1,
 nome: 'some string'
})

2. set undefined for reactive

let dadosProduto = reactive<ProdutoInterface | undefined>()
let dadosProduto: ProdutoInterface | undefined = reactive()
  • Related