marcelo.delta
marcelo.delta

Reputation: 3082

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

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

Upvotes: 2

Views: 904

Answers (1)

Busana Si
Busana Si

Reputation: 36

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()

Upvotes: 2

Related Questions