vm.$mount()

vm.$mount( [elementOrSelector] )

  • Arguments:

    • {Element | String} [elementOrSelector]
  • Returns: vm - the instance itself

  • Usage:

    If a Vue instance didn’t receive the el option at instantiation, it will be in “unmounted” state, without an associated DOM element or fragment. vm.$mount() can be used to manually start the mounting/compilation of an unmounted Vue instance.

    If no argument is provided, the template will be created as an out-of-document fragment, and you will have to use other DOM instance methods to insert it into the document yourself. If replace option is set to false, then an empty <div> will be automatically created as the wrapper element.

    Calling $mount() on an already mounted instance will have no effect. The method returns the instance itself so you can chain other instance methods after it.

  • Example:

    var MyComponent = Vue.extend({
      template: '<div>Hello!</div>'
    })
    
    // create and mount to #app (will replace #app)
    new MyComponent().$mount('#app')
    
    // the above is the same as:
    new MyComponent({ el: '#app' })
    
    // or, compile off-document and append afterwards:
    new MyComponent().$mount().$appendTo('#container')
  • See also: Lifecycle Diagram

doc_VueJS
2016-09-25 05:48:19
Comments
Leave a Comment

Please login to continue.