I have set up a basic Example Component which is bound to a Vue Instance as shown below:
<template>
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Example Component</div>
<div class="panel-body">
{{ msg }}
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data : function(){
return{
msg : "Hello"
}
},
mounted() {
console.log('Component mounted.')
}
}
</script>
Here is my app.js
file
/**
* First we will load all of this project's JavaScript dependencies including
* Vue and other libraries. This serves as a great kickoff point for developing
* powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* Next, we will create a new Vue application instance and connect it to
* the page. You can then start adding components to this application
* or customize the JavaScript scaffolding to meet your specific requirements.
*/
Vue.component('example-component', require('./components/ExampleComponent.vue'));
var firstComponent = new Vue({
el: '#app'
});
This is my HTML
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<div id="app">
<example-component></example-component>
</div>
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
How can I change the value of msg
now? There is no reference to that component anywhere. How should I proceed?
Can this be done?
var ex = Vue.component('example-component', require('./components/ExampleComponent.vue'));
ex.data = "new Value";