DOM? ?? ?? ???? HTML ?????? ?? ????????. DOM? ???? ???? ??? ??? ? ????. DOM? HTML ??? ??? ? ?? ???? JavaScript? ???? ? ???? ?? ???? ??? ?????. DOM? ?? ??? ??? ?? ??? ?? ??(?? ??)???.
? ????? ?? ??: windows7 ???, vue3 ??, DELL G3 ???.
dom?? ?????
dom? ?? ?? ???? HTML ?????? ?? ????????. ???? ??? DOM? ?? ?????. HTML ???? ???? ????? ??? ?? ??? ??? ??? ???? ???? ??? ??? ? ?? DOM? ?????.
DOM? W3C ???? ???? ?? ??? ??? ?? ??? ?? ?? ????? ?????? ?? ?? ??(DOM)??? ???.
DOM? HTML ??? ??? ? ?? ?????. JavaScript ??? ???? ? ???? ?? ??? ?????. DOM? ?? ??? ??? ?? ??? ?? ??(?? ??)???.
?? DOM? ???? ???? ??? ?? ?????. DOM? ??? ???? ???? ? ??? ??, ??? ??? ?? ? ??, ??? ?? ?? ??? ?????.
JavaScript? ???? ?? HTML ??? ???? ? ????. ?? ?? ???? ??? ??, ??, ?? ?? ??????.
???? ??? ????? JavaScript? HTML ??? ?? ??? ???? ? ??? ???. HTML ??? ??, ??, ?? ?? ???? ?? ??? ? ??? ?? ? ??? ?? ?? ??? ?? ????.
?? DOM?? ?????
React?? Vue? ????? ?? DOM? ? ?????(React-Native ? Weex) ??? ??? ??? ??? ?????.
?? , ?? ?? DOM? ??? ??? ????. ?? JavaScript ??(VNode ??)? ??? ??? ???? ??? ??? ???? ??? ??? ? ????. ??? ??? ?? DOM ????? ??? Javascript ???? ?? DOM? ?? ??? ?????. ??? ???? ?? ??(tag), ??(attrs) ? ?? ?? ??(children)?? ? ?? ??? ???? ????. ?? DOM? ??? ??? ?? ??? ? ? ???? ????. ??? ?? ?????? ?? DOM ??? ??? ?? DOM? ??? ??? ?????. vue??? ?? DOM? ??? ? ????.
<div id="app"> <p class="p">節(jié)點內(nèi)容</p> <h3>{{ foo }}</h3> </div>
VNode, vue? ? ?? ???? ??? ????, ??? ????, diff ????? ?? ???? ?? ?? ??? ?? ?? ?? ?????? dom ??? ??? ??? ???? ? ????.
Vue? DOM? ???? ?? ?? ??
Vue? MVVM ??? ???? ???? ??? ????? DOM? ????? ??????? ???? ?????? ??? ??? ?? ??? ??? ??? ????. ??? ?? DOM ?? ??(?? ??, ??? ??????? ?? DOM ??? ?? ??? ????? ?? ??? ?? ??? ???? ?) ? ????? Vue?? DOM ??? ?? ?? ?? ??? ?? ?????.
DOM API? ???? ??? ?? ????const app = new Vue({
el:"#app",
data:{
foo:"foo"
}
})
? ??? ??? ???? ??????. ?? ??? ??? Vue ?? ??? this.$el
? ?????. ???? ?? dom ???? $el
? querySelector, querySelectorAll
? ?? ???? ?? ???? ???? ??? ?? ? ????.
refs
(function anonymous( ) { with(this){return _c('div',{attrs:{"id":"app"}},[_c('p',{staticClass:"p"}, [_v("節(jié)點內(nèi)容")]),_v(" "),_c('h3',[_v(_s(foo))])])}})?? ?? ?????
$refs
? ???? ref
??? ???????. ?? ??? ???? ?????. ref ??? ?? ??? ???? ? ?? ??? ????? ?? ??, ??? ??? DOM ??? ?? ???.
v-for
?? ??? ???? ???? ?? ??? ?? ??? ref
??? ??? ????? ?? ??? ??? ????( ref? ???? ???? ????? ???. <script> ... mounted () { let elm = this.$el.querySelector('#id') } </script>?? ?? ??? ref ??? ?? Vue ?? ???? ??? ? ????:
<template> <div ref="bar">{{ foo }}</div> <MyAvatar ref="avatar" /> ... </template> <script> ... mounted () { let foo = this.$refs['bar'] // 一個dom元素 let avatar = this.$refs['avatar'] // 一個組件實例對象 } </script>
this.$el
賦值為掛載的根dom元素,我們可以直接使用$el
的querySelector, querySelectorAll
等方法獲取匹配的元素。<template> <div v-for="item in qlist" :key="item.id" ref="qitem"> <h3>{{ item.title }}</h3> <p ref="pinitem">{{ item.desc }}</p> <p :ref="'contact'+item.id">{{ item.contact }}</p> </div> ... </template> <script> ... data () { return { qlist: [ { id: 10032, title: 'abc', desc: 'aadfdcc', contact: 123 }, { id: 11031, title: 'def', desc: '--*--', contact: 856 }, { id: 20332, title: 'ghi', desc: '?/>,<{]', contact: 900 } ] } }, mounted () { let foo = this.$refs['qitem'] // 一個包含dom元素的數(shù)組 let ps = this.$refs['pinitem'] // p元素是v-for的子元素,同樣是一個數(shù)組 let contact1 = this.$refs['contact' + this.qlist[0].id] // 還是個數(shù)組 } </script>
使用組件實例的$refs
即可拿到組件上ref
屬性對應的元素。
如果ref屬性加在一個組件上,那么拿到的是這個組件的實例,否則拿到的就是dom元素了。
值得注意的是包含v-for
循環(huán)模板指令的情況,其循環(huán)元素和子元素上ref
屬性對應的都是一個數(shù)組(就算動態(tài)生成ref,也是數(shù)組):
function registerRef (vnode, isRemoval) { var key = vnode.data.ref; if (!isDef(key)) { return } var vm = vnode.context; // vnode如果有componentInstance表明是一個組件vnode,它的componentInstance屬性是其真實的根元素vm // vnode如果沒有componentInstance則不是組件vnode,是實際元素vnode,直接取其根元素 var ref = vnode.componentInstance || vnode.elm; var refs = vm.$refs; if (isRemoval) { ... } else { // refInFor是模板編譯階段生成的,它是一個布爾值,為true表明此vnode在v-for中 if (vnode.data.refInFor) { if (!Array.isArray(refs[key])) { refs[key] = [ref]; // 就算元素唯一,也會被處理成數(shù)組 } else if (refs[key].indexOf(ref) < 0) { // $flow-disable-line refs[key].push(ref); } } else { refs[key] = ref; } } }
關(guān)于這個的原因,可以從Vue關(guān)于ref處理的部分代碼得到:
Vue.directive('focus', { // 當被綁定的元素插入到 DOM 中時…… inserted: function (el) { // 聚焦元素 el.focus() } }) // 在模板中 <template> <input v-model="name" v-focus /> </template>
Vue提供了自定義指令,官方文檔給出了如下的使用方法,其中el
??? ?? ?? Instructions
Vue? ??? ?? ??? ?? ?? ???? ??? ?? ?? ??? ?????. ??? el
? dom ??? ?? ?????.rrreee ??? ?? ??? ???? ?? ?? ?? ??????? ?? ?????. ? ??? ?? ????.
? ??? vue dom? ?? ?????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? transforminvue3aimedtosimplify handlingreactivedatabyautomicallytrackingandmaningreactivity withoutequiringmanualref () ?? valueusage.itsivingtoreduceboilerplateandimprovecodeReadabilitabledevariableletandsconstasmonclicallicallicallicallicallicallicallicallicallicallicallicalliceLerplateNclateMconsconclicallicallicallicallicallicallicallicallicalliceLerplateN

??? ? ??? invueAppsareprimally handledusingthevuei18nplugin.1.installvue-i18nvianpmoryarn.2.createlocalejsonfiles (? : en.json, es.json) fortranslationMessages.3

?? : keyAttributeWithv-forInvueisSenderferperferformanCanceAndCorrectBehavior.first, ithelpsVuetrackeachelementementEficiledullyBirtlyBirtlyDiffingAlgorithMtoIndifyandUpdateOnlyWhat'Snecessary.second, itpreservescomponents, ensuri

VUE? ?? ?? ? ??? ?? ??? ??? ????? ?? : 1. V-Once ???? ???? ?? ???? ???? ???? ????? ????. 2. ?? ???? ???? Vue-Virtual-Scroller ????? ??? ?? ??? ??? ?? ? ??????. 3. ?? ???? ??? ?? Keep-Alive ?? V-Once? ?? ?? ?? ??; 4. ?? ? ?? ? ???? ???? ?? ? ??? ????? ? ??? ??? ????. 5. V-FOR?? ?? ? ??, ???? ??? ??? ??? ?? ?? ??? ???? ?? ??? ?? ? ?? ??? ?????. ??? ??? ?? ???? ????? ???? ? ????.

SPR (Server-SiderEndering)? ????? ??? ??? ??? ????

ToaddtransitionsandanimationsinVue,usebuilt-incomponentslikeand,applyCSSclasses,leveragetransitionhooksforcontrol,andoptimizeperformance.1.WrapelementswithandapplyCSStransitionclasseslikev-enter-activeforbasicfadeorslideeffects.2.Useforanimatingdynam

NextTick? VUE?? DOM ???? ? ??? ???? ? ?????. ???? ???? VUE? ?? DOM? ?????? ??? ?? ??? ?? "Tick"?? DOM? ?? ?????. ??? ???? ? DOM? ?????? ?? ???? ?? NextTick? ???????. ???? ????? ??? ????. ???? ? DOM ??? ???, DOM ??? ???? ?? ?????? ???? ?? ??? ???? ?????. ???? ??? ???? ?? ?????. $ NextTick? ?? ?? ????, ??? ? ???? ???? Async/Await? ?????. ?? ???? ??? ?????. ??? ??? ?????. ???? ?? ?? ????? ???? ??? ?? ?? ? ?? ?? ????? ?? ? ? ????.

VUE ?? ?? ?????? ????? ???? ???? ??? ??? ???? ?? ??, ??? ? ??? ????? ??????. 1. ?? ??? ?? ?? ??, ???? ?? ?? ? ???? ?? ??? ??? ?? ??? ?? ????????. 2. ??? ???? ???? ?? SCSS ?? CSS ??? ??????. 3. ?? ??? ???? ??? ?? ???? ???? ?? Eslint ? Pretier? ?????. 4. ?? ?? ???? ?? ??? ??? ?????. 5. VITE ? ?? ??? ???? NPM ???? ????? ? ??? ?????. 6. Semver ??? ?? ?? ? ? ?? ? Changelogs? ??????.
