筆記:Vue數據響應式綁定原理—觀源碼

沒有具體對應源碼分析,只是閱讀源碼的筆記,等以後學好點再寫成文章數組

Vue

  • self,構造生成的this。源碼分析

  • root根元素。this

  • els帶指令的全部元素,經過querySelectorAll獲取,涉及getDirSelectors,返回"[v-text],[v-show]"(屬性選擇器)
    bindings對data裏的進行綁定?spa

處理節點processNode

  • 提取全部attributes,getAttributes返回數組,元素是對象,包含name、value。code

    [{name:"v-text",value:"message"},{}]
    使用了el.attributes, 這個返回一下結果,太多,用getAttributes過濾一下

    clipboard.png

  • 對提取的全部指令進行解析,parseDirective,返回如下結果,對於v-show="isShow"
    clipboard.png對象

  • 綁定指令bindDirectiveip

    key是要指向data的key,因此實際上是attr的value
  • bindDirective的最後用bindAccessors進行defineProperty設定get、setget

    defineProperty綁定的set、get是在vm上,因此初始化只須要給vm的相應屬性賦值
  • 初始化源碼

    遍歷bindings並賦值到vm
相關文章
相關標籤/搜索