监视属性(watch)
<h1>监视属性watch主要是用于对一个属性是否发生变化进行监视,并且可以接收两个参数newValue和oldValue,分别表示变化后和变化前的属性值</h1>
<h1>watch</h1>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=4c2e7e7af8c92fcebbd73df77621e794&amp;file=file.png" alt="" /></p>
<h2>可以监视属性也可以监视函数</h2>
<h2>另一种写法</h2>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=4bc34a27ebd3ee8cbb9c6fa14494008f&amp;file=file.png" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c8f6d1289fa74bf8f16bbd964e86691b&amp;file=file.png" alt="" /></p>
<h1>深度监视</h1>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=8cdaced3d8bb51acf3985fc3060edb33&amp;file=file.png" alt="" />
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=56f59ef3d46656e2a59a5c571decf8f0&amp;file=file.png" alt="" /></p>
<h2>错误写法</h2>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=7d989ee4ee2a2848e5296d63009565e7&amp;file=file.png" alt="" /></p>
<h2>因为<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=49d1227e7daee59207e01233454c33f2&amp;file=file.png" alt="" /></h2>
<h2>这样写它不会去看里面的内容,看的只是numbers存放内容的地址</h2>
<h2>正确写法</h2>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=4844880ca75d50d05edd1f6408cd5c86&amp;file=file.png" alt="" />
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=6ce3714bf49b82eb84c2825a7a387dd0&amp;file=file.png" alt="" /></p>
<h1>简写</h1>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=2559ff9438c754b41427c5cfe5138caf&amp;file=file.png" alt="" />
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=f6b1b3359a76340f1e1733fd40532d3d&amp;file=file.png" alt="" /></p>
<h2>当监视属性与计算属性都能实现时可以选用计算属性,但是面临异步操作时只能用监视属性</h2>
<h2>如果想要延迟1s改变</h2>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=de1d9faa0866baa57c15a50ba309ecc2&amp;file=file.png" alt="" /></p>
<h2>这里的return返回给了箭头函数,fullName没有接收到返回值</h2>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=2b751513e4d03012443d7a79c9e8f4cc&amp;file=file.png" alt="" /></p>
<h2>watch则可以正常实现延迟1s,因为watch不用返回值,而是自己手写的</h2>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c4de70b0132f632e2bf3ae9832d4ba24&amp;file=file.png" alt="" /></p>