关于render: h => h(App)和components: { App }的区别

关于render: h => h(App)和components: { App }的区别

在main.js中:常会有

new Vue({
el: ‘#app’,
router,//实例化,表示会使用
render: h => h(App)//vue2.0写法

//以下是vue1.0的写法
//components: { App },//注册组件信息
// template: ‘’//简写的模板调用组件的标签
})

components: { App }
template: ‘’
或者

render: h => h(App)的代码。
render:function(h){
      return h(App)
      }
render:function(createElement){
  return createElement(App)    
  }
实际上这两行代码的作用是一样的,
只是render: h => h(App)是 vue2.0的语法

  components: { App }是vue1.0的语法,

作用是渲染视图,并给el挂载

猜你喜欢

转载自blog.csdn.net/song854601134/article/details/109542616