Vue3 学习笔记 —— 响应式数据的判断

本文介绍了Vue中的ref、reactive和readonly三种响应式工具的使用,并通过示例展示了如何使用isRef、isReactive、isReadonly和isProxy进行检测。在setup函数中,创建了ref、reactive和readonly对象并打印了它们的检测结果,演示了如何判断一个对象是否为响应式或代理对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

isRef

  • 判断一个值是否为一个 ref 对象

isReactive

  • 判断一个对象是否是由 reactive创建的响应式代理

isReadonly

  • 判断一个对象是否是由 readonly 创建的只读代理

isProxy

  • 判断一个对象是否是由 reactivereadonly 创建的代理

测试

  • 代码:
<template>
  <div></div>
</template>

<script lang="ts">

import { defineComponent, ref, reactive, readonly, isRef, isReactive, isReadonly, isProxy} from 'vue';


export default defineComponent({
  name: 'Child',

  setup() {
    let testRef = ref('ref')
    console.log('isRef:', isRef(testRef))

    let testReactive = reactive({})
    console.log('isReative: ', isReactive(testReactive))

    let testReadOnly = readonly({name: '12'})
    console.log('isReadonly: ', isReadonly(testReadOnly))

    console.log('isProxy: ', isProxy(testRef))
    console.log('isProxy: ', isProxy(testReactive))
    console.log('isProxy: ', isProxy(testReadOnly))

  }

});
</script>

  • 截图:
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tanleiDD

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值