原文:https://www.cnblogs.com/CyLee/p/8425183.html

手动挂载$mount()

如果没有挂载的话,没有关联的 DOM 元素。是获取不到$el的。

https://vuejs.org/v2/api/#vm-mount

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, render off-document and append afterwards:
var component = new MyComponent().$mount()
document.getElementById('app').appendChild(component.$el)

  

posted on 2019-07-08 10:32  gzh4455  阅读(479)  评论(0编辑  收藏  举报