-
ref reactive toRef toRefs
<script setup>
import { ref, reactive, toRef, toRefs} from "vue";
const count = ref(0);
const obj = reactive({
name: "lidysun",
age: 32,
contact:{
wx:'820262236',
email:'820262236@qq.com'
}
});
const name1 = toRef(obj,'name')
const {name,age,contact} = toRefs(obj)
</script>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
import { computed } from "vue";
const text = computed(() => {
return count.value % 2 == 0 ? "偶数" : "奇数";
});
const text = computed({
get() {
return count.value % 2 == 0 ? "偶数" : "奇数";
},
set() {},
});
-
监听器watch
import { watch } from "vue";
watch(
count,
newCount => {
obj.age = age.value + newCount;
},
{ immediate: true }
);
watch([() => obj.age, text], (newVal, oldVal) => {
console.log("newVal", newVal, ";", "oldVal", oldVal);
});