-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
运行时/编译时前端框架都有哪些优缺点? #62
Comments
运行时纯运行时框架比较好理解,举一个例子 编译-运行时为什么称 // template
<div>
<h1 v-if="true" />
<h2 v-else />
</div>
// 编译后的render 函数 伪代码
// h('div', { children: true ? h('h1') : h('h2') })
<div>
{ true ? <h1 /> : <h2 /> }
</div>
// h('div', { children: true ? h('h1') : h('h2') })
<div>{s ?? <h1 />}</div>
<div>
<h1 v-if="s != null" />
</div>
// 转换出来的代码为 h('div', { children: s != null && h('h1') }) 可以看到在使用模板的时候有许多限制,这也是为什么很多 既然我使用编译了,那就贯彻到底。虽然模板在 js 层面有很多限制,但是也得到了更多的能力,比如 <div>{true ? <h1 /> : <h2 />}</div>
// h('div', { children: true ? h('h1') : h('h2') })
;<div>
<h1 v-if="true" />
<h2 v-else />
</div>
const h1 = h('h1')
const h2 = h('h2')
// h('div', { children: true ? h1 : h2 }) 这样再次生成 虚拟 Dom 的时候就节省两个函数执行的开销,还可以体现编译好处的就是
纯编译对于纯编译框架 总结,主要对比了 利弊二者之间的利弊其实挺明显的,纯运行时框架最大的利就是不会与 编译的利就是拓展了很多能力,觉得 Web 语法不爽,甚至可以搞一套自己喜欢的语法,只要最后编译为 |
简单总结:纯编译框架在做到性能优化的同时失去了灵活性,react就是纯粹的运行时框架,vue则是中庸之道在各个框架吸取精华 前端小白 用过的框架也只有react 所以说的很片面 肯定也有错的地方,欢迎指正 |
发生问题的场景
主流的前端框架从实现原理讲,一般分为:
React
)Vue
)Svelte
)你能从以下角度回答该问题么?
需要解决的问题
最佳答案评选标准
最佳答案
悬赏中,欢迎作答...
答题同学须知
答题规范:请在
一次评论
中完成作答,后续修改也请编辑该评论,而不是追加新的评论评选标准:最佳答案由
围观同学
的 👍 和卡颂共同决定评选时间:一般是问题发布24小时后评选,如果问题发布当天回答数较少,问题悬赏金额可能增加,同时悬赏时间也会增加
围观同学须知
对于你满意的答案,请不要吝惜你的 👍,这是评选最佳答案的依据
非答题的评论
会被删除,问题相关讨论请在赏金猎人群中进行The text was updated successfully, but these errors were encountered: