以Vue.js为标准来比较React.js,Svelte.js的API
大致比较,根据具体情况会有不一样的情况
API比较
Vue.js 3 Composition API | React.js Hooks API | Svelte.js |
---|---|---|
生命周期 | useEffect | 生命周期 |
watch/watchEffect | useEffect | $: { } |
computed | useMemo/useEffect | $: { } |
ref/reactive | useState | $: |
v-html | dangerouslySetInnerHTML | { @html } |
v-if | js三元运算 | { #if } |
v-for | map() | { #each } |
v-model | useState+onChange | bind:value |
@click | onClick | on:click |
ref | useRef | this |
:class | className | class: |
provide/inject | useContext | context API |
eventbus* | publish/subscribe* | publish/subscribe* |
*:需要第三方库
转载自:https://segmentfault.com/a/1190000042288970