-
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>
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);
});