Vue 2.0源碼分析-update

Vue 的 _update 是實例的一個私有方法,它被調用的時機有 2 個,一個是首次渲染,一個是數據更新的時候;由于我們這一章節只分析首次渲染部分,數據更新部分會在之后分析響應式原理的時候涉及。_update 方法的作用是把 VNode 渲染成真實的 DOM,它的定義在 src/core/instance/lifecycle.js 中:

Vue.prototype._update = function (vnode: VNode, hydrating?: boolean) {const vm: Component = thisconst prevEl = vm.$elconst prevVnode = vm._vnodeconst prevActiveInstance = activeInstanceactiveInstance = vmvm._vnode = vnode// Vue.prototype.__patch__ is injected in entry points// based on the rendering backend used.if (!prevVnode) {// initial rendervm.$el = vm.__patch__(vm.$el, vnode, hydrating, false /* removeOnly */)} else {// updatesvm.$el = vm.__patch__(prevVnode, vnode)}activeInstance = prevActiveInstance// update __vue__ referenceif (prevEl) {prevEl.__vue__ = null}if (vm.$el) {vm.$el.__vue__ = vm}// if parent is an HOC, update its $el as wellif (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {vm.$parent.$el = vm.$el}// updated hook is called by the scheduler to ensure that children are// updated in a parent's updated hook.
}

_update 的核心就是調用 vm.__patch__ 方法,這個方法實際上在不同的平臺,比如 web 和 weex 上的定義是不一樣的,因此在 web 平臺中它的定義在 src/platforms/web/runtime/index.js 中:

Vue.prototype.__patch__ = inBrowser ? patch : noop

可以看到,甚至在 web 平臺上,是否是服務端渲染也會對這個方法產生影響。因為在服務端渲染中,沒有真實的瀏覽器 DOM 環境,所以不需要把 VNode 最終轉換成 DOM,因此是一個空函數,而在瀏覽器端渲染中,它指向了 patch 方法,它的定義在 src/platforms/web/runtime/patch.js中:

import * as nodeOps from 'web/runtime/node-ops'
import { createPatchFunction } from 'core/vdom/patch'
import baseModules from 'core/vdom/modules/index'
import platformModules from 'web/runtime/modules/index'// the directive module should be applied last, after all
// built-in modules have been applied.
const modules = platformModules.concat(baseModules)export const patch: Function = createPatchFunction({ nodeOps, modules })

該方法的定義是調用 createPatchFunction 方法的返回值,這里傳入了一個對象,包含 nodeOps 參數和 modules 參數。其中,nodeOps 封裝了一系列 DOM 操作的方法,modules 定義了一些模塊的鉤子函數的實現,我們這里先不詳細介紹,來看一下 createPatchFunction 的實現,它定義在 src/core/vdom/patch.js 中:

const hooks = ['create', 'activate', 'update', 'remove', 'destroy']export function createPatchFunction(backend) {let i, jconst cbs = {}const { modules, nodeOps } = backendfor (i = 0; i < hooks.length; ++i) {cbs[hooks[i]] = []for (j = 0; j < modules.length; ++j) {if (isDef(modules[j][hooks[i]])) {cbs[hooks[i]].push(modules[j][hooks[i]])}}}return function patch(oldVnode, vnode, hydrating, removeOnly) {if (isUndef(vnode)) {if (isDef(oldVnode)) invokeDestroyHook(oldVnode)return}let isInitialPatch = falseconst insertedVnodeQueue = []if (isUndef(oldVnode)) {// empty mount (likely as component), create new root elementisInitialPatch = truecreateElm(vnode, insertedVnodeQueue)} else {const isRealElement = isDef(oldVnode.nodeType)if (!isRealElement && sameVnode(oldVnode, vnode)) {// patch existing root nodepatchVnode(oldVnode, vnode, insertedVnodeQueue, removeOnly)} else {if (isRealElement) {// mounting to a real element// check if this is server-rendered content and if we can perform// a successful hydration.if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) {oldVnode.removeAttribute(SSR_ATTR)hydrating = true}if (isTrue(hydrating)) {if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {invokeInsertHook(vnode, insertedVnodeQueue, true)return oldVnode} else if (process.env.NODE_ENV !== 'production') {warn('The client-side rendered virtual DOM tree is not matching ' +'server-rendered content. This is likely caused by incorrect ' +'HTML markup, for example nesting block-level elements inside ' +'<p>, or missing <tbody>. Bailing hydration and performing ' +'full client-side render.')}}// either not server-rendered, or hydration failed.// create an empty node and replace itoldVnode = emptyNodeAt(oldVnode)}// replacing existing elementconst oldElm = oldVnode.elmconst parentElm = nodeOps.parentNode(oldElm)// create new nodecreateElm(vnode,insertedVnodeQueue,// extremely rare edge case: do not insert if old element is in a// leaving transition. Only happens when combining transition +// keep-alive + HOCs. (#4590)oldElm._leaveCb ? null : parentElm,nodeOps.nextSibling(oldElm))// update parent placeholder node element, recursivelyif (isDef(vnode.parent)) {let ancestor = vnode.parentconst patchable = isPatchable(vnode)while (ancestor) {for (let i = 0; i < cbs.destroy.length; ++i) {cbs.destroy[i](ancestor)}ancestor.elm = vnode.elmif (patchable) {for (let i = 0; i < cbs.create.length; ++i) {cbs.create[i](emptyNode, ancestor)}// #6513// invoke insert hooks that may have been merged by create hooks.// e.g. for directives that uses the "inserted" hook.const insert = ancestor.data.hook.insertif (insert.merged) {// start at index 1 to avoid re-invoking component mounted hookfor (let i = 1; i < insert.fns.length; i++) {insert.fns[i]()}}} else {registerRef(ancestor)}ancestor = ancestor.parent}}// destroy old nodeif (isDef(parentElm)) {removeVnodes(parentElm, [oldVnode], 0, 0)} else if (isDef(oldVnode.tag)) {invokeDestroyHook(oldVnode)}}}invokeInsertHook(vnode, insertedVnodeQueue, isInitialPatch)return vnode.elm}
}

createPatchFunction 內部定義了一系列的輔助方法,最終返回了一個 patch 方法,這個方法就賦值給了 vm._update 函數里調用的 vm.__patch__。

在介紹 patch 的方法實現之前,我們可以思考一下為何 Vue.js 源碼繞了這么一大圈,把相關代碼分散到各個目錄。因為前面介紹過,patch 是平臺相關的,在 Web 和 Weex 環境,它們把虛擬 DOM 映射到 “平臺 DOM” 的方法是不同的,并且對 “DOM” 包括的屬性模塊創建和更新也不盡相同。因此每個平臺都有各自的 nodeOps 和 modules,它們的代碼需要托管在 src/platforms 這個大目錄下。

而不同平臺的 patch 的主要邏輯部分是相同的,所以這部分公共的部分托管在 core 這個大目錄下。差異化部分只需要通過參數來區別,這里用到了一個函數柯里化的技巧,通過 createPatchFunction 把差異化參數提前固化,這樣不用每次調用 patch 的時候都傳遞 nodeOps 和 modules 了,這種編程技巧也非常值得學習。

在這里,nodeOps 表示對 “平臺 DOM” 的一些操作方法,modules 表示平臺的一些模塊,它們會在整個 patch 過程的不同階段執行相應的鉤子函數。這些代碼的具體實現會在之后的章節介紹。

回到 patch 方法本身,它接收 4個參數,oldVnode 表示舊的 VNode 節點,它也可以不存在或者是一個 DOM 對象;vnode 表示執行 _render 后返回的 VNode 的節點;hydrating 表示是否是服務端渲染;removeOnly 是給 transition-group 用的,之后會介紹。

patch 的邏輯看上去相對復雜,因為它有著非常多的分支邏輯,為了方便理解,我們并不會在這里介紹所有的邏輯,僅會針對我們之前的例子分析它的執行邏輯。之后我們對其它場景做源碼分析的時候會再次回顧 patch 方法。

先來回顧我們的例子:

var app = new Vue({el: '#app',render: function (createElement) {return createElement('div', {attrs: {id: 'app'},}, this.message)},data: {message: 'Hello Vue!'}
})

然后我們在 vm._update 的方法里是這么調用 patch 方法的:

// initial render
vm.$el = vm.__patch__(vm.$el, vnode, hydrating, false /* removeOnly */)

結合我們的例子,我們的場景是首次渲染,所以在執行 patch 函數的時候,傳入的 vm.$el 對應的是例子中 id 為 app 的 DOM 對象,這個也就是我們在 index.html 模板中寫的 <div id="app">, vm.$el 的賦值是在之前 mountComponent 函數做的,vnode 對應的是調用 render 函數的返回值,hydrating 在非服務端渲染情況下為 false,removeOnly 為 false。

確定了這些入參后,我們回到 patch 函數的執行過程,看幾個關鍵步驟。

const isRealElement = isDef(oldVnode.nodeType)
if (!isRealElement && sameVnode(oldVnode, vnode)) {// patch existing root nodepatchVnode(oldVnode, vnode, insertedVnodeQueue, removeOnly)
} else {if (isRealElement) {// mounting to a real element// check if this is server-rendered content and if we can perform// a successful hydration.if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) {oldVnode.removeAttribute(SSR_ATTR)hydrating = true}if (isTrue(hydrating)) {if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {invokeInsertHook(vnode, insertedVnodeQueue, true)return oldVnode} else if (process.env.NODE_ENV !== 'production') {warn('The client-side rendered virtual DOM tree is not matching ' +'server-rendered content. This is likely caused by incorrect ' +'HTML markup, for example nesting block-level elements inside ' +'<p>, or missing <tbody>. Bailing hydration and performing ' +'full client-side render.')}}// either not server-rendered, or hydration failed.// create an empty node and replace itoldVnode = emptyNodeAt(oldVnode)}// replacing existing elementconst oldElm = oldVnode.elmconst parentElm = nodeOps.parentNode(oldElm)// create new nodecreateElm(vnode,insertedVnodeQueue,// extremely rare edge case: do not insert if old element is in a// leaving transition. Only happens when combining transition +// keep-alive + HOCs. (#4590)oldElm._leaveCb ? null : parentElm,nodeOps.nextSibling(oldElm))
}

由于我們傳入的 oldVnode 實際上是一個 DOM container,所以 isRealElement 為 true,接下來又通過 emptyNodeAt 方法把 oldVnode 轉換成 VNode 對象,然后再調用 createElm 方法,這個方法在這里非常重要,來看一下它的實現:

function createElm(vnode,insertedVnodeQueue,parentElm,refElm,nested,ownerArray,index
) {if (isDef(vnode.elm) && isDef(ownerArray)) {// This vnode was used in a previous render!// now it's used as a new node, overwriting its elm would cause// potential patch errors down the road when it's used as an insertion// reference node. Instead, we clone the node on-demand before creating// associated DOM element for it.vnode = ownerArray[index] = cloneVNode(vnode)}vnode.isRootInsert = !nested // for transition enter checkif (createComponent(vnode, insertedVnodeQueue, parentElm, refElm)) {return}const data = vnode.dataconst children = vnode.childrenconst tag = vnode.tagif (isDef(tag)) {if (process.env.NODE_ENV !== 'production') {if (data && data.pre) {creatingElmInVPre++}if (isUnknownElement(vnode, creatingElmInVPre)) {warn('Unknown custom element: <' + tag + '> - did you ' +'register the component correctly? For recursive components, ' +'make sure to provide the "name" option.',vnode.context)}}vnode.elm = vnode.ns? nodeOps.createElementNS(vnode.ns, tag): nodeOps.createElement(tag, vnode)setScope(vnode)/* istanbul ignore if */if (__WEEX__) {// ...} else {createChildren(vnode, children, insertedVnodeQueue)if (isDef(data)) {invokeCreateHooks(vnode, insertedVnodeQueue)}insert(parentElm, vnode.elm, refElm)}if (process.env.NODE_ENV !== 'production' && data && data.pre) {creatingElmInVPre--}} else if (isTrue(vnode.isComment)) {vnode.elm = nodeOps.createComment(vnode.text)insert(parentElm, vnode.elm, refElm)} else {vnode.elm = nodeOps.createTextNode(vnode.text)insert(parentElm, vnode.elm, refElm)}
}

createElm 的作用是通過虛擬節點創建真實的 DOM 并插入到它的父節點中。 我們來看一下它的一些關鍵邏輯,createComponent 方法目的是嘗試創建子組件,這個邏輯在之后組件的章節會詳細介紹,在當前這個 case 下它的返回值為 false;接下來判斷 vnode 是否包含 tag,如果包含,先簡單對 tag 的合法性在非生產環境下做校驗,看是否是一個合法標簽;然后再去調用平臺 DOM 的操作去創建一個占位符元素。

vnode.elm = vnode.ns? nodeOps.createElementNS(vnode.ns, tag): nodeOps.createElement(tag, vnode)

接下來調用 createChildren 方法去創建子元素:

createChildren(vnode, children, insertedVnodeQueue)function createChildren(vnode, children, insertedVnodeQueue) {if (Array.isArray(children)) {if (process.env.NODE_ENV !== 'production') {checkDuplicateKeys(children)}for (let i = 0; i < children.length; ++i) {createElm(children[i], insertedVnodeQueue, vnode.elm, null, true, children, i)}} else if (isPrimitive(vnode.text)) {nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(String(vnode.text)))}
}

createChildren 的邏輯很簡單,實際上是遍歷子虛擬節點,遞歸調用 createElm,這是一種常用的深度優先的遍歷算法,這里要注意的一點是在遍歷過程中會把 vnode.elm 作為父容器的 DOM 節點占位符傳入。

接著再調用 invokeCreateHooks 方法執行所有的 create 的鉤子并把 vnode push 到 insertedVnodeQueue 中。

if (isDef(data)) {invokeCreateHooks(vnode, insertedVnodeQueue)
}function invokeCreateHooks(vnode, insertedVnodeQueue) {for (let i = 0; i < cbs.create.length; ++i) {cbs.create[i](emptyNode, vnode)}i = vnode.data.hook // Reuse variableif (isDef(i)) {if (isDef(i.create)) i.create(emptyNode, vnode)if (isDef(i.insert)) insertedVnodeQueue.push(vnode)}
}

最后調用 insert 方法把 DOM 插入到父節點中,因為是遞歸調用,子元素會優先調用 insert,所以整個 vnode 樹節點的插入順序是先子后父。來看一下 insert 方法,它的定義在 src/core/vdom/patch.js 上。

insert(parentElm, vnode.elm, refElm)function insert(parent, elm, ref) {if (isDef(parent)) {if (isDef(ref)) {if (ref.parentNode === parent) {nodeOps.insertBefore(parent, elm, ref)}} else {nodeOps.appendChild(parent, elm)}}
}

insert 邏輯很簡單,調用一些 nodeOps 把子節點插入到父節點中,這些輔助方法定義在 src/platforms/web/runtime/node-ops.js 中:

export function insertBefore(parentNode: Node, newNode: Node, referenceNode: Node) {parentNode.insertBefore(newNode, referenceNode)
}export function appendChild(node: Node, child: Node) {node.appendChild(child)
}

其實就是調用原生 DOM 的 API 進行 DOM 操作,看到這里,很多同學恍然大悟,原來 Vue 是這樣動態創建的 DOM。

在 createElm 過程中,如果 vnode 節點不包含 tag,則它有可能是一個注釋或者純文本節點,可以直接插入到父元素中。在我們這個例子中,最內層就是一個文本 vnode,它的 text 值取的就是之前的 this.message 的值 Hello Vue!。

再回到 patch 方法,首次渲染我們調用了 createElm 方法,這里傳入的 parentElm 是 oldVnode.elm 的父元素,在我們的例子是 id 為 #app div 的父元素,也就是 Body;實際上整個過程就是遞歸創建了一個完整的 DOM 樹并插入到 Body 上。

最后,我們根據之前遞歸 createElm 生成的 vnode 插入順序隊列,執行相關的 insert 鉤子函數,這部分內容我們之后會詳細介紹。

總結


那么至此我們從主線上把模板和數據如何渲染成最終的 DOM 的過程分析完畢了,我們可以通過下圖更直觀地看到從初始化 Vue 到最終渲染的整個過程。

我們這里只是分析了最簡單和最基礎的場景,在實際項目中,我們是把頁面拆成很多組件的,Vue 另一個核心思想就是組件化。那么下一章我們就來分析 Vue 的組件化過程。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/209294.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/209294.shtml
英文地址,請注明出處:http://en.pswp.cn/news/209294.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

思維鏈(CoT)提出者 Jason Wei:關于大語言模型的六個直覺

文章目錄 一、前言二、主要內容三、總結 &#x1f349; CSDN 葉庭云&#xff1a;https://yetingyun.blog.csdn.net/ 一、前言 Jason Wei 的主頁&#xff1a;https://www.jasonwei.net/ Jason Wei&#xff0c;一位于 2020 年從達特茅斯學院畢業的杰出青年&#xff0c;隨后加盟了…

大數據安全保障的四種關鍵技術

隨著大數據時代的到來&#xff0c;數據安全保障的重要性日益凸顯。大數據安全保障涉及多種關鍵技術&#xff0c;以下是四種關鍵技術的詳細介紹。 數據加密技術 數據加密技術是大數據安全保障的核心技術之一。它通過將明文數據轉化為密文數據&#xff0c;以保護數據的機密性和完…

CSS中 設置文字下劃線 的幾種方法

在網頁設計和開發中&#xff0c;我們經常需要對文字進行樣式設置&#xff0c;包括字體,顏色&#xff0c;大小等&#xff0c;其中&#xff0c;設置文字下劃線是一種常見需求 一 、CSS種使用 text-decoration 屬性來設置文字的裝飾效果&#xff0c;包括下劃線。 常用的取值&…

Visual Studio 2015 中 FFmpeg 開發環境的搭建

Visual Studio 2015 中 FFmpeg 開發環境的搭建 Visual Studio 2015 中 FFmpeg 開發環境的搭建新建控制臺工程拷貝并配置 FFmpeg 開發文件測試FFmpeg 開發文件的下載鏈接 Visual Studio 2015 中 FFmpeg 開發環境的搭建 新建控制臺工程 新建 Win32 控制臺應用程序。 具體流程&…

炫酷不止一面:探索JavaScript動畫的奇妙世界(下)

&#x1f90d; 前端開發工程師&#xff08;主業&#xff09;、技術博主&#xff08;副業&#xff09;、已過CET6 &#x1f368; 阿珊和她的貓_CSDN個人主頁 &#x1f560; 牛客高級專題作者、在牛客打造高質量專欄《前端面試必備》 &#x1f35a; 藍橋云課簽約作者、已在藍橋云…

proftpd安全加固:限制用戶FTP登錄

其實無所謂安全加固&#xff0c;因為proftp默認就是限制用戶FTP登錄的&#xff0c;這里有點凌亂得研究和實驗了proftpd如何進行限制的&#xff0c;以及可能的放開限制。懂了這些才能更好的進行防護配置。 RootLogin指令其實主要作用就是啟用ROOT訪問。通常&#xff0c;proftpd在…

【Fastadmin】一個完整的輪播圖功能示例

目錄 1.效果展示&#xff1a; 列表 添加及編輯頁面同 2.建表&#xff1a; 3.使用crud一鍵生成并創建控制器 4.html頁面 add.html edit.html index.php 5.js頁面 6.小知識點 1.效果展示&#xff1a; 列表 添加及編輯頁面同 2.建表&#xff1a; 表名&#xff1a;fa_x…

【LabVIEW學習】5.數據通信之TCP協議,控制電腦的一種方式

一。tcp連接以及寫數據&#xff08;登錄&#xff09; 數據通信--》協議--》TCP 1.tcp連接 創建while循環&#xff0c;中間加入事件結構&#xff0c;創建tcp連接&#xff0c;寫入IP地址與端口號 2.寫入tcp數據 登錄服務器除了要知道IP地址以及端口以外&#xff0c;需要用戶名與密…

中通單號查詢,中通快遞物流查,備注需要的單號記錄

批量查詢中通快遞單號的物流信息&#xff0c;并對需要的單號記錄進行備注。 所需工具&#xff1a; 一個【快遞批量查詢高手】軟件 中通快遞單號若干 操作步驟&#xff1a; 步驟1&#xff1a;運行【快遞批量查詢高手】軟件&#xff0c;第一次使用的朋友記得先注冊&#xff0c…

快速冪(C語言)

前言 快速冪算法一般用于高次冪取模的題目中&#xff0c;比如求3的10000次方對7取模。這時候有些同學會說&#xff1a;這還不簡單&#xff1f;我直接調用pow函數然后對結果%7不得了么&#xff1f;可是3的10000次方這么龐大的數字&#xff0c;真的能儲存在計算機里么&#xff1f…

HTML行內元素與塊級元素的區別(超詳細)

目錄 行內元素&#x1f338;常見的行內元素&#x1f338;行內元素&#xff08;內聯元素&#xff09;的特性 塊級元素&#x1f338;常見的塊級元素&#x1f338;塊級元素的特性 相互轉換(display)&#x1f338;行內塊狀元素的特性 行內元素 &#x1f338;常見的行內元素 <s…

c#學習相關系列之as和is的相關用法

一、子類和父類的關系 public class Program{static void Main(string[] args){Animal animal new Dog();// Dog dog (Dog)new Animal(); 編譯成功&#xff0c;運行報錯Dog dog (Dog)animal;Dog dog new Dog();Animal animal dog; //等價于Animal animal new Dog();}}pub…

java多生產者多消費者模擬實現

package com.example.springboottestone.main;import java.util.LinkedList; import java.util.Queue;/*** 多生產者多消費者模型是指多個生產者線程同時向緩沖區中添加數據&#xff0c;同時多個消費者線程從緩沖區中獲取數據的并發模型。這種模型適用于需要高并發處理數據的場…

企業計算機服務器中了eking勒索病毒怎么辦,eking勒索病毒解密數據恢復

隨著計算機網絡技術的不斷發展與應用&#xff0c;企業的生產運營效率得到了極大提升&#xff0c;但網絡安全威脅一直存在&#xff0c;網絡威脅的技術也在不斷更新&#xff0c;給企業的數據安全帶來了嚴重威脅。在本月&#xff0c;云天數據恢復中心陸續接到很多企業的求助&#…

C++ Qt開發:Qt的安裝與配置

Qt是一種C編程框架&#xff0c;用于構建圖形用戶界面&#xff08;GUI&#xff09;應用程序和嵌入式系統。Qt由Qt公司&#xff08;前身為Nokia&#xff09;開發&#xff0c;提供了一套跨平臺的工具和類庫&#xff0c;使開發者能夠輕松地創建高效、美觀、可擴展的應用程序。其被廣…

Python---random庫

目錄 基本隨機數函數(): rand.seed() random() 擴展隨機數函數(): random庫包含兩類函數&#xff1a;基本隨機數函數&#xff0c;擴展隨機數函數 基本隨機數函數:seed(),random() 擴展隨機數函數&#xff1a;randint,getrandbits(),uniform(),randrange(),choice(),shuff…

猴子吃桃問題(for循環)

一只猴子第一天摘下若干個桃子&#xff0c;當即吃了一半&#xff0c;還不過癮&#xff0c;又多吃了一個&#xff1b;第二天早上又將剩下的桃子吃掉一半&#xff0c;又多吃了一個。以后每天早上都吃了前一天剩下的一半加一個。到第N天早上想再吃時&#xff0c;見只剩下一個桃子了…

ECS云主機容量大于2TB,初始化Linux數據盤(parted)

本文為您介紹當容量大于2TB時&#xff0c;如何在Linux環境下適用parted分區工具初始化數據盤。 操作場景 本文以“CentOS 7.6 64位”操作系統為例&#xff0c;介紹當磁盤容量大于2TB時&#xff0c;如何使用parted分區工具在Linux操作系統中為數據盤設置分區&#xff0c;操作回…

SAP UI5 walkthrough step6 Modules

在SAPUI5 中&#xff0c;資源通常用作Modules&#xff0c;這個我們將用Message Toast 來實現告警功能 修改controller.js webapp/controller/App.controller.js sap.ui.define(["sap/ui/core/mvc/Controller","sap/m/MessageToast" ], (Controller, Mes…

Python中的Alpha-Beta剪枝算法:優化博弈樹搜索

標題&#xff1a;Python中的Alpha-Beta剪枝算法&#xff1a;優化博弈樹搜索 摘要&#xff1a;Alpha-Beta剪枝算法是一種用于優化博弈樹搜索的算法&#xff0c;能夠降低搜索的時間復雜度&#xff0c;提高程序的性能和效率。本文將介紹Alpha-Beta剪枝算法的原理&#xff0c;以及…