We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<input type="text" id="input"> <script> let i = document.querySelector('#input'); let obj = {}; let temp = {}; Object.defineProperty(obj,'name',{ get(){ // 取obj值时触发 return temp.name; }, set(val){ //设置obj值时触发,且会调用get temp.name = val; i.value = val; } }) i.addEventListener('input',function(){ obj.name = this.value; }) </script>
这里加了temp变量是因为如果直接给obj设置值的话代码会写为
set(val){ obj.name = val }
obj.name本质就是调用set方法,从而导致循环调用所以要加个temp临时变量。
beforeCreate
created
beforeMount
mounted
beforeUpdate
updated
由于数据更改导致的虚拟 DOM 重新渲染和打补丁,在这之后会调用该钩子。
当这个钩子被调用时,组件 DOM 已经更新,所以你现在可以执行依赖于 DOM 的操作。然而在大多数情况下,你应该避免在此期间更改状态,因为这可能会导致更新无限循环。
该钩子在服务器端渲染期间不被调用。
beforeDestroy
destroyed
The text was updated successfully, but these errors were encountered:
No branches or pull requests
VUE
vue 指令
v-model的简单实现
这里加了temp变量是因为如果直接给obj设置值的话代码会写为
obj.name本质就是调用set方法,从而导致循环调用所以要加个temp临时变量。
vue 的生命周期
beforeCreate
created
beforeMount
mounted
beforeUpdate
updated
由于数据更改导致的虚拟 DOM 重新渲染和打补丁,在这之后会调用该钩子。
当这个钩子被调用时,组件 DOM 已经更新,所以你现在可以执行依赖于 DOM 的操作。然而在大多数情况下,你应该避免在此期间更改状态,因为这可能会导致更新无限循环。
该钩子在服务器端渲染期间不被调用。
beforeDestroy
destroyed
vue API
The text was updated successfully, but these errors were encountered: