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!
CodePudding user response:
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>
CodePudding user response: