通过上一篇文章尝鲜vue3.0-从ToDoList开始的介绍,你们能够初步了解一下vue3.0的简单写法。接下来,我描述一下尤大总结的整体变化,以及目前成熟的rfcs(语法变化)。html
Performance(性能)vue
slot语法变化react
directiveapi
//动态转入指令名称 <div v-bind:[key]="value"></div> <div v-on:[event]="handler"></div> // import { h, resolveComponent, resolveDirective, withDirectives } from 'vue' export default { render() { const comp = resolveComponent('some-global-comp') const fooDir = resolveDirective('foo') const barDir = resolveDirective('bar') // <some-global-comp v-foo="x" v-bar="y" /> return withDirectives( h(comp), [fooDir, this.x], [barDir, this.y] ) } }
为了运行tree-shaking,将api经过全局的import导出性能优化
//好比 import {nextTick,h,} from 'vue'
删除 v-bind.sync,用v-model代替数据结构
函数式组件必须为函数app
{ functional: true }
<template functional>
//与2.X相比 //只使用props和slot(data和childre就没了) //使用的新的api inject代替injections //parent被删除,首选使用props 和 injections //listeners 将包括在 attrs 属性中 import { inject } from 'vue' import { demo } from './Demo' const FunctionalComp = (props, { slots, attrs, emit }) => { const demoCom = inject(demo) return h('div', `Using demo ${demoCom}`) }
import { defineAsyncComponent } from 'vue' const AsyncComp = defineAsyncComponent(() => import('./Foo.vue'))
改变Vue行为的global API被移到由新的apicreateApp
方法建立的应用实例中,他们的只做用于app实例中,不改变Vue行为的gloabl API经过import使用,见第5点
dom
h
使用import从vue中引用,见第五点props, { slots, attrs, emit }
export default { render() { return h( 'div', //之前 //{ // domProps: { innerHTML: '' }, //on: { click: foo }, //key: 'foo', //class: ['foo', 'bar'], //style: { color: 'red' }, //attrs: { id: 'foo' }, //}, // 扁平化的数据结构 { innerHTML: '', id: 'app', onClick:clickFn, key: 'foo', class: ['foo', 'bar'], style: { color: 'red' } }, [ h('span', 'world') ] ) } }
目前变化的api,东西太多讲不完。大概就是上一遍新增的ref,reactive,watchEffect
等api异步
transition变化ide
<transition>
做为组件的根将再也不触发转换class变化
v-enter-from
替换 v-enter
v-leave-from
替换 v-leave
v-appear-from
替换 v-appear
$on, $off, $once
在vue2.0里面,能够用声明式的$emit
可触发父组件中的方法,可是也能使用命令式的$on, $off, $once
也能实现。算是一种重载,也考虑到也不必暴露组件实例
属性的强制行为
当值为布尔值时再也不移除属性。相反,它被设置为attr="false"。若要删除该属性,请使用null或undefined。
//vue2.0中原话 //若是 isButtonDisabled 的值是 null、undefined 或 false,则 disabled attribute 甚至不会被包含在渲染出来的 <button> 元素中 <button v-bind:disabled="isButtonDisabled">Button</button>
弃用 >>>
和 /deep/
//使用这种 ::v-deep(.bar) {}
::v-global(.foo) {}
当前,从父节点传入的插槽内容同时受到父节点和子节点的样式影响。没法显式的建立以slot内容为目标的样式,或者不影响slot内容的样式,vue3.0中增长::v-slotted()
::v-slotted(.foo) {}
目前的改动简单的列举了一下,vue3.0改动很大,可是更可能是整理简化api,增长更多开发者须要的api,内部语法调整,以及性能优化。仍是尽可能的贴合之前开发习惯,下降升级成本。因此你们不用担忧,能够愉快的接受3.0
喜欢的话,大佬们能够点赞收藏,后续再更新😄
下一篇尝鲜vue3.0-tyepscript开发组件(3)