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

180
Visualizações
how do i use property from within vue- to outside of vue

I am using vue2.5. I am simply trying to have a variable outside of vue (traditional javascript or jquery) access a property from the vue model. The property in this case is sun. I want the data that would be found in sun to display within Const planet. How can i make that work? I tried using const planet = $app.sun but that doesn't work. Not sure how to make this work. Please see my example

const planet=""
//document.getElementById("cat").append("myName");

new Vue({
  el: "#app",
  data: {
   earth:"this is a ball",
    sun:"s",

  },
  methods: {
    toggle: function(){
   this.sun="a ball of stars"


    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">

{{sun}}
<br>
<button v-on:click="toggle()">magic

</button>
<div id="planet">
</div>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can set Vue in variable and then access $data:

var vm = new Vue({
  el: "#app",
  data: {
     earth:"this is a ball",
     sun:"s"
  },
  methods: {
    toggle: function(){
      this.sun="a ball of stars"
    }
  }
})
const planet = vm.$data.sun
document.getElementById("cat").append(planet);
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  {{sun}}
  <br>
  <button v-on:click="toggle()">magic</button>
  <div id="planet">
  </div>
</div>
<p>outside of Vue</p>
<div id="cat"></div>

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