詳解Vue監(jiān)聽數(shù)據(jù)變化原理
本人最近在學(xué)習(xí)Vue,從網(wǎng)上查詢了很多關(guān)于Vue監(jiān)聽數(shù)據(jù)變化原理,稍微整理精簡一下做下分享。
淺度監(jiān)聽
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>淺度監(jiān)聽</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <script src="../js/vue1.0.js"></script> <script src="../js/vue-resource.js"></script> <script> window.onload = function(){ var vm = new Vue({ el:'#box', data:{ a:111, b:2 } }); vm.$watch('a',function(){ alert('發(fā)生變化了'); }); document.onclick = function(){ vm.a = 1; } } </script> </head> <body> <div id="box"> {{a}} <hr> {} </div> </body> </html>
深度監(jiān)聽
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>深度監(jiān)聽</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <script src="../js/vue1.0.js"></script> <script src="../js/vue-resource.js"></script> <script> window.onload = function(){ var vm = new Vue({ el:'#box', data:{ json:{name:'abcdef',age:'16'}, b:2 } }); vm.$watch('json',function(){ alert('發(fā)生變化了'); },{deep:true}); document.onclick = function(){ vm.json.name = "aaaaaa"; } } </script> </head> <body> <div id="box"> {{json | json}} <hr> {} </div> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue預(yù)覽圖片和視頻的幾種實(shí)現(xiàn)方式
本文主要介紹了Vue預(yù)覽圖片和視頻的幾種實(shí)現(xiàn)方式,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07Vue2安裝使用MonacoEditor方式(自定義語法,自定義高亮,自定義提示)
這篇文章主要介紹了Vue2安裝使用MonacoEditor方式(自定義語法,自定義高亮,自定義提示),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04Vue?2中實(shí)現(xiàn)CustomRef方式防抖節(jié)流
這篇文章主要為大家介紹了Vue?2中實(shí)現(xiàn)CustomRef方式防抖節(jié)流示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02基于vue組件實(shí)現(xiàn)猜數(shù)字游戲
這篇文章主要為大家詳細(xì)介紹了基于vue組件實(shí)現(xiàn)猜數(shù)字游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11Vue3+axios+Mock.js實(shí)現(xiàn)登錄功能的示例代碼
本文主要介紹了Vue3+axios+Mock.js實(shí)現(xiàn)登錄功能的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05vue實(shí)現(xiàn)兩級select聯(lián)動+input賦值+select選項(xiàng)清空
這篇文章主要介紹了vue實(shí)現(xiàn)兩級select聯(lián)動+input賦值+select選項(xiàng)清空過程,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08vue 導(dǎo)航錨點(diǎn)_點(diǎn)擊平滑滾動,導(dǎo)航欄對應(yīng)變化詳解
這篇文章主要介紹了vue 導(dǎo)航錨點(diǎn)_點(diǎn)擊平滑滾動,導(dǎo)航欄對應(yīng)變化詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08