Vue render: h => h(App) $mount

$mount()手动挂载

当Vue实例没有el属性时,则该实例尚没有挂载到某个dom中;

 

假如需要延迟挂载,可以在之后手动调用vm.$mount()方法来挂载。例如:

new Vue({
 
//el: '#app',
 
router,
 
render: h => h(App)
 
// render: x => x(App)
 
// 这里的render: x => x(App)是es6的写法
 
// 转换过来就是: 暂且可理解为是渲染App组件
 
// render:(function(x){
 
// return x(App);
 
// });
 
}).$mount("#app");

或者

new Vue({
 
el: '#app',
 
router,
 
render: h => h(App)
 
// render: x => x(App)
 
// 这里的render: x => x(App)是es6的写法
 
// 转换过来就是: 暂且可理解为是渲染App组件
 
// render:(function(x){
 
// return x(App);
 
// });
 
});
new Vue({

  render: h=> h(App)

}). $mount(root)

Vue 2.0新增的函数,可以直接给绑定节点渲染一个vue组件,如果在Vue 1.x下,就应该使用

 
new Vue({
    el: '#app',
    components: { App }
});
 

然后在页面中写入标记:

<div id="app">
    <app></app>
</div>

猜你喜欢

转载自www.cnblogs.com/carpenterzoe/p/10522240.html