Vue的runtimecompiler和runtimeonly

本文深入探讨了Vue.js中两种不同的渲染方式:runtime-compiler和runtime-only。通过代码实例,详细解析了从模板到AST再到render函数的过程,以及直接使用render函数创建虚拟DOM节点的方法。对比了两种方式的性能差异,帮助开发者理解Vue的渲染机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. runtime-compiler

import Vue from 'vue';
import App from './App.vue';

 export default  new Vue({
       el:'#app', 
       template: '<APP/>',
       components: {APP}
   })

// 渲染过程 template-> ast -> render -> vdom ->UI
上面例子可以换种写法

 export default  new Vue({
       el:'#app', 
       render: function (createElement){
         //createElement('标签' ,{标签属性},['内容‘])
        // return createElement('h2',{class:'box'},['hello world',createElement('botton',['按钮‘])]);
        return createElement(App);
       }
   })

2. runtime-only

import Vue from 'vue';
import App from './App.vue';

export default new Vue({
  el: '#app',
  render: h => h(App)
})

// 渲染过程 render -> vdom ->UI;
比较 : 1. only性能更高;底层代码量更少

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值