当前位置: 首页 > news >正文

众筹网站搭建关键词搜索点击软件

众筹网站搭建,关键词搜索点击软件,免费的奖励网站有哪些,网站开发python和c 哪个好以下是 Vue3 中defineExpose的使用方法&#xff1a; 基本概念 defineExpose是 Vue3 中的一个工具函数&#xff0c;是仅能在<script setup>中使用的函数&#xff0c;用于显式暴露组件内部的属性或方法给父组件使用2。在 Vue3 的<script setup>中&#xff0c;组件的…

以下是 Vue3 中defineExpose的使用方法:

基本概念

defineExpose是 Vue3 中的一个工具函数,是仅能在<script setup>中使用的函数,用于显式暴露组件内部的属性或方法给父组件使用2。在 Vue3 的<script setup>中,组件的状态和方法默认是私有的,父组件即使通过ref引用子组件实例,也无法访问其中的内容,使用defineExpose可以打破这一限制.

基本用法

defineExpose的基本语法是defineExpose(exposedObject)。其中,exposedObject是一个对象,用于定义要暴露的属性或方法

示例

  • 暴露函数
<!-- 子组件ChildComponent.vue -->
<template><h2>子组件</h2>
</template>
<script setup>
import { ref } from 'vue';
const message = ref('Hello from Child Component');
// 定义一个供父组件调用的函数
function childMethod() {console.log('子组件方法被调用!');
}
// 使用defineExpose暴露message和childMethod
defineExpose({message,childMethod
});
</script>
<!-- 父组件 -->
<template><h1>父组件</h1><ChildComponent ref="childRef" /><button @click="callChildMethod">调用子组件方法</button>
</template>
<script setup>
import { ref } from 'vue';
import ChildComponent from './ChildComponent.vue';
const childRef = ref(null);
function callChildMethod() {// 通过ref调用子组件暴露的方法console.log(childRef.value.message);childRef.value.childMethod();
}
</script>
  • 暴露数据
<!-- 子组件 -->
<script setup>
import { ref } from 'vue';
// 子组件内部的状态和方法
const count = ref(0);
// 通过defineExpose暴露给父组件
defineExpose({count
});
</script>
<template><p>计数器子组件:{{ count }}</p>
</template>
<!-- 父组件 -->
<script setup>
import { ref } from 'vue';
import Counter from './Counter.vue';
// 通过ref获取子组件实例
const counterRef = ref(null);
function callChildMethod() {console.log('子组件计数值:', counterRef.value.count);
}
</script>
<template><Counter ref="counterRef" /><button @click="callChildMethod">获取子组件计数值</button>
</template>

注意事项

  • defineExpose应该放在<script setup>的末尾,因为任何在它之后声明的变量或函数都不会被自动包含在暴露的对象中4。
  • 当组件中包含<script setup>和普通<script>时,<script>中定义的数据和方法不会被暴露

<template><!-- 组件模板 -->
</template><script setup>import { ref, onMounted } from 'vue';// 这些内容会被 expose 出去const count = ref(0);function increment() {count.value++;}// 定义暴露出去的 APIdefineExpose({count,increment});// 这个函数不会被 expose 出去,因为它在 defineExpose 调用之后定义function decrement() {count.value--;}
</script>
http://www.fp688.cn/news/162111.html

相关文章:

  • 企业网站优化方案范本超级优化大师
  • 建立网站需要什么手续建网站要多少钱
  • 江西求做网站seo研究中心好客站
  • wordpress 滑块验证上海网站seo公司
  • 商城网站建设开发公司近期国内热点新闻事件
  • 一台云服务器可以做多个网站世界最新新闻
  • 大学生怎么做网站seo联盟
  • 潮州网站建设销售推广方案
  • 电商网站开发周期小时seo
  • 百度推广怎么做的上海网站优化
  • 一个网站做无限关键词网络推广工作是做什么的
  • 大型商城网站开发搜索引擎推广的三种方式
  • 做外贸怎么能上国外网站seo刷网站
  • 龙华网站建设设计seo与sem的区别与联系
  • 以前做视频的网站产品推广的渠道有哪些
  • 网站大部分都是jsp做的24小时最新国际新闻
  • 关于网站建设中原创文章的一些想法千川推广官网
  • 微信如何建立网站微信管理软件哪个最好
  • 王爷的杂货铺长春关键词优化平台
  • 做旅游网站的原因网络广告文案案例
  • 值得信赖的深圳app开发公司网站推广优化c重庆
  • 专业网站制作公司seo综合查询工具下载
  • 如何用ps做网站设计图百度云app
  • 哪些做园林的网站软文是什么东西
  • 做网站教程免费网站推广软件下载
  • wordpress 完整主题下载地址商品标题seo是什么意思
  • 专业网站建设新闻学做网站培训班要多少钱
  • 网站建设公司兴田德润实惠关键词下载
  • 做网站有什么好处购买模板建站
  • 医院手机网站建设百度怎么推广产品