• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

135
Vistas
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 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda