To create a Vue.js instance and mount it to an element, follow these steps:
<script>
tag:<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
tag:<script>
var app = new Vue({
// Vue options
// ...
});
</script>
<script>
var app = new Vue({
el: '#my-app',
data: {
message: 'Hello, Vue!'
}
});
</script>
In the above example, the el
option specifies the CSS selector identifying the element to mount the Vue instance to, and the data
option defines the data properties for the instance.
el
option in your Vue instance:<div id="my-app">
{{ message }}
</div>
In this case, the Vue instance will be mounted to the <div>
element with the id 'my-app'
.
Note: Make sure to add the <script>
tag containing the Vue instance after the HTML element you want to mount it to.