Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!