Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
Vue3 object render invalid,but vue2 success

A simple demo

HTML Template

<div id="app">{{ temp.progress }}</div>

Instantiate object

class Temp {
    constructor () {
        this.start()
    }
    progress = 0

    start () {
        setInterval(() => {
            this.progress += 1
        }, 1000)
    }
}

const temp = new Temp()

vue2 render success (page display 1,2,3,4,5.......)

new Vue({
    el: '#app',
    data () {
        return { temp }
    },
})

but vue3 render invalid (page display always 0)

Vue.createApp({
    data() {
        return { temp }
    }
}).mount('#app')
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Vue 3 creates Proxy object rather than augmenting the original object in place. Conceptually you can think of it as (in vue3 code):

const dataObj = { temp };
const data = reactive(dataObj);

dataObj is your raw object and data is the proxy. They are two different objects. The important thing is that data is reactive, but dataObj is not. All the direct mutations on the dataObj cannot be observed, because the observing utilities are all in the stub methods of the proxy object.

What your Temp class is doing, effectively it is mutating the raw object - that is what this refers to.

If your component does not own its data, i.e. the data needs to be externalized and passed in, and will be managed (mutated) externally, you will need to create a reactive object and pass it into your component.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda