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é)點(diǎn)內(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é)點(diǎn)內(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'] // 一個(gè)dom元素 let avatar = this.$refs['avatar'] // 一個(gè)組件實(shí)例對象 } </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'] // 一個(gè)包含dom元素的數(shù)組 let ps = this.$refs['pinitem'] // p元素是v-for的子元素,同樣是一個(gè)數(shù)組 let contact1 = this.$refs['contact' + this.qlist[0].id] // 還是個(gè)數(shù)組 } </script>
使用組件實(shí)例的$refs
即可拿到組件上ref
屬性對應(yīng)的元素。
如果ref屬性加在一個(gè)組件上,那么拿到的是這個(gè)組件的實(shí)例,否則拿到的就是dom元素了。
值得注意的是包含v-for
循環(huán)模板指令的情況,其循環(huán)元素和子元素上ref
屬性對應(yīng)的都是一個(gè)數(shù)組(就算動態(tài)生成ref,也是數(shù)組):
function registerRef (vnode, isRemoval) { var key = vnode.data.ref; if (!isDef(key)) { return } var vm = vnode.context; // vnode如果有componentInstance表明是一個(gè)組件vnode,它的componentInstance屬性是其真實(shí)的根元素vm // vnode如果沒有componentInstance則不是組件vnode,是實(shí)際元素vnode,直接取其根元素 var ref = vnode.componentInstance || vnode.elm; var refs = vm.$refs; if (isRemoval) { ... } else { // refInFor是模板編譯階段生成的,它是一個(gè)布爾值,為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)于這個(gè)的原因,可以從Vue關(guān)于ref處理的部分代碼得到:
Vue.directive('focus', { // 當(dāng)被綁定的元素插入到 DOM 中時(shí)…… 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

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

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

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

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

1. PHP ?? ?? ? ?? ?????? Laravel MySQL VUE/React ??? ? ?? ??? ???? ??? ?? ?? ??? ?? Laravel MySQL VUE/React ??? ? ?? ?????. 2. ???? ?? (REDIS), ?????? ???, CDN ? ??? ?? ???????. 3. ?? ???, CSRF ??, HTTPS, ???? ??? ? ?? ??? ??? ???????. 4. ? ??? ??, ?? ??, ??, ???, ?? ?? ? ?? ??? ??? ???? ? ? ??? ??? ?? ????.

vue ?? ????? ??? ?, ???? ?? ?? ???? ??? ?????. 1. ????? ??? ??? ?? ? ??? ???? ????? ???????. 2. V-IF ? V- ?? ??, ??? ??? ??? ???? ???? ????? ???????. 3. ?? ??? ??? ????? ?? ??? ???? ?? ?? ???? ???? ?? ?? $ ??? ???????. 4. ?? ?? ?? ??? ???? ?? ??? ????, ?? ?? ?? ??/???? ???????. 5. ???? ??? ?? ??, ? ???? ??? ??? ??????? ???????.
