Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Passing values to vue

I can pass a value from a main to my vue instance (another script) but won’t work 🙁

<script>
let data = [{id:'1'}] //JUST SAMPLE

function pass_to_vue(data){
    return data
}
</script> 
 
<script>
var app = new Vue({
el: '#app',
    data: {
        external_value: pass_to_vue // HERE RECEIVE EXTERNAL VALUE
    }
})
</script>

Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Please take a look at snippet below:

let ext = [{id:'1'}] 
function pass_to_vue(data){
  return data
}
document.querySelector('#ext').innerText = JSON.stringify(ext)

var app = new Vue({
  el: '#demo',
  data() {
    return {
      external_value: '' 
    }
  },
  mounted() {
    this.external_value = pass_to_vue(ext)
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  vue value
  {{ external_value }}
  <p>change id</p>
  <input v-model="external_value[0].id" />
  <hr />
</div>
<p>external value</p>
<p id="ext"></p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading