色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

詳解vue3中渲染函數的非兼容變更

瀏覽:2日期:2022-10-02 18:02:26
渲染函數API變更

此更改不會影響到<template>用戶

h現在全局導入,而非作為參數傳遞給渲染函數 渲染函數參數更改為在有狀態組件和函數組件之間更加一致 vnode現在又一個扁平的prop結構Render函數參數

// 2.0 渲染函數export default { render(h) { return h(’div’) }}// 3.x語法export default { render() { return h(’div’) }}渲染函數簽名更改

// 2.xexport default { render(h) { return h(’div’) }}// 3.ximport { h, reactive } from ’vue’export default { setup(prop, {slots, attrs, emit}) { const state = reactive({ count: 0 }) function increment() { state.count++ } // 返回render函數 return () => h( ’div’, { onClick: increment }, state.count ) }}VNode Props 格式化

// 2.x{ class: [’button’, ’is-outlined’], style: {color: ’#fffff’}, attr: {id: ’submit’}, domProps: {innerHTML: ’’}, on: {click: submitForm}, key: ’submit-button’}// 3.x VNode的結構是扁平的{ class: [’button’, ’is-outlined’], style: { color: ’#34495E’ }, id: ’submit’, innerHTML: ’’, onClick: submitForm, key: ’submit-button’}slot統一

更改了普通slot和作用域slot

this.$slots現在將slots作為函數公開 移除this.$scopedSlots

// 2.xh(LayoutComponent, [ h(’div’, {slot: ’header’}, this.header), h(’div’, {slot: ’header’}, this.header)])// 作用域slot:// 3.xh(LayoutComponent, {}, { header: () => h(’div’, this.header), content: () => h(’div’, this.content)})// 需要以編程方式引入作用域slot時,他們現在被統一在了$slots選項中// 2.x的作用域slotthis.$scopedSlots.header// 3.x的寫法this.$slots.header移除$listeners

$listeners對象在vue3中已經移除,現在事件監聽器是$attrs的一部分

在vue2中,可以使用this.attrs和this.attrs和this.listeners分別訪問傳遞給組件的attribute和時間監聽器,結合inheritAttrs: false,開發者可以將這些attribute和監聽器應用到其他元素,而不是根元素

<template><label> <input type='text' v-bind='$attrs' v-on='$listeners'></label></template><script> export default { inheritAttrs: false }</script>

在vue的虛擬DOM中,事件監聽器現在只是以on為前綴的attribute,這樣就成了attrs對象的一部分,這樣attrs對象的一部分,這樣listeners就被移除了

<template> <label> <input type='text' v-bind='$attrs' /> </label></template><script>export default { inheritAttrs: false}// 如果這個組件接收一個 id attribute 和一個 v-on:close 監聽器,那么 $attrs 對象現在將如下所示{ id: ’my-input’, onClose: () => console.log(’close Event Triggered’)}</script>$attrs現在包括class和style

現在的$attr包含所有的attribute,包括class和style

在2.x中,虛擬dom會對class和style進行特殊處理,所以他們不包括在$attr中在使用inheritAttr: false的時候會產生副作用

$attrs 中的 attribute 不再自動添加到根元素中,而是由開發者決定在哪添加。 但是 class 和 style 不屬于 $attrs,仍然會應用到組件的根元素:

<template> <label> <input type='text' v-bind='$attrs' /> </label></template><script>export default { inheritAttrs: false}</script><!-- 寫入 --><my-component class='my-class'></my-component><!-- vue2 將生成 --><label class='my-class'> <input type='text' /></label><!-- vue3 將生成 --><label> <input type='text' /></label>

以上就是詳解vue3中渲染函數的非兼容變更的詳細內容,更多關于vue 渲染函數非兼容變更的資料請關注好吧啦網其它相關文章!

標簽: Vue
相關文章:
主站蜘蛛池模板: 欧美成人福利视频 | 国产高清晰在线播放 | 精品国产亚洲一区二区在线3d | 日韩精品永久免费播放平台 | 国产一级真人毛爱做毛片 | 亚洲国产综合人成综合网站00 | 久久亚洲精品成人 | 日本精品国产 | 怡红院在线观看在线视频 | 日韩一级精品久久久久 | 九九在线观看精品视频6 | 成人午夜网站 | 九色愉拍自拍 | 国产在线观看网址你懂得 | 亚洲精品综合一区二区三区在线 | 在线视频亚洲 | 国产成人综合久久精品亚洲 | 欧美一级久久久久久久大片 | 欧美黄a| 国产亚洲视频在线播放大全 | 欧美亚洲国产人成aaa | 精品国产成人高清在线 | 天堂男人2021av | 在线视频久草 | 亚洲综合国产一区二区三区 | 国内真实愉拍系列情侣自拍 | 在线欧洲成人免费视频 | 热99re久久国超精品首页 | 日韩中文精品亚洲第三区 | 久草在线最新视频 | 成年人在线网站 | 国产一级在线现免费观看 | 欧美三级成版人版在线观看 | 日本理论在线 | 久久久久久久国产精品毛片 | 国产不卡在线观看视频 | 亚洲韩精品欧美一区二区三区 | 久久久久久日本一区99 | 久久久久久久久久久福利观看 | 中文字幕在线播放视频 | 欧美亚洲免费久久久 |