Vue3 isRef

本文通过一个 Vue 单文件组件(SFC)示例,展示了如何使用 `ref` 和 `reactive` 函数创建响应式属性,并利用 `isRef` 函数检查对象是否为 `ref` 包装。`ref` 用于创建响应式引用,而 `reactive` 则用于使整个对象变得响应式。在模板中,`isRef` 被用来判断 `count` 和 `val` 是否为 `ref` 对象,从而在页面上展示相应的结果。
摘要由CSDN通过智能技术生成

isRef:检查一个对象是否为 ref 包装过的对象。

实例:

<template>
  <p>The count.num is:{{ count.num}}</p>
  <p>Is the count isRef:{{ isResult }}</p>
  <p>The val is:{{ val}}</p>
  <p>Is the val isRef:{{ isRes }}</p>
</template>

<script lang="ts">
import { ref, reactive, isRef } from 'vue'
export default {
  setup() {
    const val = ref(3)
    const count = reactive({
      num: 5,
    })
    const isRes = isRef(val)
    const isResult = isRef(count)
    return {
      val,
      count,
      isRes,
      isResult,
    }
  },
}
</script>

页面效果:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值