-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathHome.vue
More file actions
80 lines (66 loc) · 1.75 KB
/
Copy pathHome.vue
File metadata and controls
80 lines (66 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<script setup>
/*
export default {
setup(){
console.log('setup')
},
created() {
console.log('created')
},
mounted() {
console.log('mounted')
}
}
*/
import {ref, reactive, computed, watch, watchEffect, onMounted, onUnmounted} from "vue";
const refData = ref({name:'zhangsan',age:30});
const reactiveData = reactive({name:'zhangsan',age:30});
const names = ref([
{name:'小猫'},
{name:'小狗'},
{name:'小猪'},
{name:'小爱'},
]);
const search = ref('小爱');
const martchNames = computed(()=>{
return names.value.filter(x=>x.name.includes(search.value))
});
const handleClick = ()=>{
refData.value.name = '张三'
stopEffect();
};
// watch(search,(newSearch,preSearch)=>{
// console.log('触发onchange事件:',newSearch,preSearch)
// });
watch([search,names],([newSearch,newNames],[preSearch,preNames])=>{
console.log('触发onchange事件:',newSearch,preSearch,newNames,preNames)
});
const stopEffect = watchEffect(()=>{
console.log('触发了立即执行的onchange事件:',search.value);
})
onMounted(()=>{
console.log('页面渲染前执行...')
});
onUnmounted(()=>{
console.log('组件注销前执行')
});
defineProps({
posts:Array,
message:String
});
</script>
<template>
<div class="home">
<h2>{{message}}</h2>
<input type="text" v-model="search">
<p>{{search}}</p>
<p v-for="(item,index) in martchNames" :key="index">{{item.name}}</p>
<p>redData:{{refData.name}}--{{refData.age}}</p>
<p>redData:{{reactiveData.name}}--{{reactiveData.age}}</p>
<button @click="handleClick">点击改变张三</button>
<button @click="names.pop()">删除一个names</button>
<button @click="stopEffect">停止监听立即改变事件</button>
</div>
</template>
<style scoped>
</style>