vue.js

关注公众号 jb51net

关闭
首页 > 网络编程 > JavaScript > javascript类库 > vue.js > Vue3中unref写法

Vue3中unref的写法代码示例

作者:唐人街都是苦瓜脸

Vue3中多种响应式实现方式,包括ref、unref、isRef、reactive等,这篇文章主要介绍了Vue3中unref写法的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下

在工作学习前端的过程中见到了这样一种写法,于是我就探究了一下

unref(editForm).open()

1. editForm

const editForm = ref()

2. unref

import { unref } from 'vue'

3. unref(editForm)

4. .open()

完整代码含义

代码示例

<template>
  <BasePage>
    <Button @click="add">新增</Button>
    <EditForm ref="editForm" />
  </BasePage>
</template>

<script setup>
import { ref, unref } from 'vue'
import EditForm from './edit-form.vue'

const editForm = ref()

const add = () => {
  // 获取 EditForm 组件实例并调用 open 方法
  unref(editForm).open()
}
</script>

注意事项

const add = () => {
  const formInstance = unref(editForm)
  if (formInstance && typeof formInstance.open === 'function') {
    formInstance.open()
  }
}

总结 

到此这篇关于Vue3中unref写法的文章就介绍到这了,更多相关Vue3中unref写法内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文