feat(computed): 添加计算属性功能实现
- 实现了 ComputedRefImpl 类来管理计算属性 - 添加了 computed 函数用于创建计算属性 - 在 ReactiveEffect 中添加 computed 属性引用 - 将 computed 导出到 reactivity 和 vue 主包 - 添加了 isFunction 工具函数判断函数类型 - 创建了计算属性的 HTML 示例文件进行演示
This commit is contained in:
26
packages/vue/examples/reactivity/computed.html
Normal file
26
packages/vue/examples/reactivity/computed.html
Normal file
@@ -0,0 +1,26 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Document</title>
|
||||
<script src="../../dist/vue.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
<script>
|
||||
const { reactive,effect,computed } = Vue
|
||||
const obj=reactive({
|
||||
name:'张三'
|
||||
})
|
||||
const computedObj= computed(()=>{
|
||||
return '姓名:'+obj.name
|
||||
})
|
||||
effect(()=>{
|
||||
document.querySelector('#app').innerText=computedObj.value
|
||||
})
|
||||
setTimeout(()=>{
|
||||
obj.name='李四'
|
||||
},2000)
|
||||
</script>
|
||||
</html>
|
||||
Reference in New Issue
Block a user