How to create instances in Vue.js

In this tutorial, we will learn how to create instances in Vue.js. Vue instance are the way to access the properties and methods passed in Vue Class options.

Method 1 : Creating Direct Instance

Create File app.html

      <title>VueJs Instance</title>
      <script type = "text/javascript" src = ""></script>
      <div id = "component_test">
      <script type = "text/javascript" src = "js/vue_component.js"></script>

Create File vue_component.js

var  vm = new Vue({
   el: '#component_test',
   data: {
      firstname : "Ria",
      lastname  : "Singh",
      address    : "Mumbai"
   methods: {
      mydetails : function() {
         return "I am "+this.firstname +" "+ this.lastname;

Method 2 : Create Instance of Extended Component

var _obj = { fname: "Raj", lname: "Singh"};

// must use function when in Vue.extend()
var Component = Vue.extend({
data: function () {
   return _obj
methods: {
   asquare: function () {
      this.fname = 'Chetan';
var myComponentInstance = new Component();

Now, run this code and create instance in vue.js


How to create components in vue.js

For more Vue.js Tutorials visit Vue.js page.

If you like this, share this.

Follow us on FacebookTwitterTumblrLinkedInYouTube.