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

八度 网站建设关于做网站建设公司你应该知道的

八度 网站建设,关于做网站建设公司你应该知道的,asp.net网站开发上,玩具 东莞网站建设 技术支持以下是 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 -- templateh2子组件/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 !-- 父组件 -- templateh1父组件/h1ChildComponent refchildRef /button clickcallChildMethod调用子组件方法/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 templatep计数器子组件{{ 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 templateCounter refcounterRef /button clickcallChildMethod获取子组件计数值/button /template 注意事项 defineExpose应该放在script setup的末尾因为任何在它之后声明的变量或函数都不会被自动包含在暴露的对象中4。当组件中包含script setup和普通script时script中定义的数据和方法不会被暴露 template!-- 组件模板 -- /templatescript setupimport { 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.w-s-a.com/news/778071/

相关文章:

  • 株洲网站建设联系方式东莞凤岗网站制作
  • 小纯洁网站开发如何注册域名
  • 网上做试卷的网站如何把刚做的网站被百度抓取到
  • 滕州网站建wordpress用户中心按钮不弹出
  • 清远新闻最新消息福建seo搜索引擎优化
  • 凡客建站网微信网站怎么做的
  • 网站建设费怎么写会计科目行业网站建设公司
  • 网站里的友情链接网站建设个人简历的网页
  • 佛山自助建站软件湖南seo优化推荐
  • 免费微信微网站模板下载不了优化人员配置
  • wordpress 导航网站主题画流程图的网站
  • 皮卡剧网站怎样做排名网
  • 网站开发 兼职哪个网站是做安全教育
  • 商品展示类网站怎么用群晖nas做网站
  • 长腿蜘蛛wordpresssem优化推广
  • 中国铁路建设监理协会官方网站深圳福田区怎么样
  • 互联网网站开发发展wordpress文章自定义栏目
  • 众筹网站平台建设工信部网站备案系统
  • 网站301重定向代码wordpress 加子目录
  • 淄博网站制作优化推广asp做学生信息网站
  • 海口招商建设有限公司网站淮安哪有专业做网站的公司
  • 喀什哪有做网站的国内正规seo网络推广
  • 网站设计初步规划公司网页打不开是什么原因
  • 深圳企业网站建设推广服务php做的商城网站设计论文
  • 韩雪冬网站手机网站开发 宽度
  • 奉贤专业做网站新手怎么做企业网站
  • 做网站用哪几个端口 比较好手机号网站源码
  • 手机免费代理ip网站那个旅游网站做攻略最好
  • 西安做网站找哪家公司好苏州专业网站建设开发
  • dedecms如何做网站网站设计实施方案