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

做网站柳州重庆森林经典台词 凤梨罐头

做网站柳州,重庆森林经典台词 凤梨罐头,域名停靠网站下载大全免费工能,翻译网站平台建设目录 create-vue创建项目 一. 父子通信 1. 父传子 2. 子传父 二. 模版引用(通过ref获取实例对象) 1.基本使用 2.defineExpose 三. 跨层通信 - provide和inject 1. 作用和场景 2. 跨层传递普通数据 3. 跨层传递响应式数据 4. 跨层传递方法 create-vue创建项目 npm ini…

目录

create-vue创建项目

一. 父子通信

1. 父传子

2. 子传父

 二. 模版引用(通过ref获取实例对象)

1.基本使用

 2.defineExpose

三. 跨层通信 - provide和inject

1. 作用和场景

2. 跨层传递普通数据

3. 跨层传递响应式数据

4. 跨层传递方法


create-vue创建项目

npm init vue@latest

 

一. 父子通信

1. 父传子

  1. 父组件中给子组件绑定属性

  2. 子组件内部通过props选项接收数据

// 父组件
<script setup>
import sonVue from "./son.vue";
</script>
<template><sonVue msg="this is msg" />
</template>
<style scoped></style>
// 子组件
<script setup>
//子组件内部通过props选项接收数据
const props = defineProps({msg: String,
});
</script>
<template><div>{{ msg }}</div>
</template>
<style scoped></style>

2. 子传父

  1. 父组件中给子组件标签通过@绑定事件

  2. 子组件内部通过 emit 方法触发事件

// 父组件
<script setup>
import sonVue from "./son.vue";
// 获取传递子组件传递的值 val
const getMessage = (val) => {console.log(val);
};
</script>
<template><!-- 1.绑定自定义事件 getMessage --><sonVue @getMessage="getMessage" />
</template>
<style scoped></style>
// 子组件
<script setup>
//2. 生成emit方法
const emit = defineEmits(["getMessage"]);const sendMsg = () => {//3.触发自定义事件,并传递参数emit("getMessage", "this is msg");
};
</script>
<template><button @click="sendMsg">测试</button>
</template>
<style scoped></style>

 二. 模版引用(通过ref获取实例对象)

概念:通过 ref标识 获取真实的 dom对象或者组件实例对象

1.基本使用

  1. 调用ref函数生成一个ref对象

  2. 通过ref标识绑定ref对象到标签  

<script setup>
import { ref } from "vue";
//1.调用ref函数得到ref对象
const TestRef = ref(null);//输出得到一个RefImpl对象
console.log(TestRef);
</script><template><!-- 2. 通过ref标识绑定ref对象 --><div ref="TestRef">测试一下</div>
</template>
<style scoped></style>

 2.defineExpose

  • 默认情况下在 <script setup>语法糖下组件内部的属性和方法是不开放给父组件访问的,为了显式暴露某些属性或方法,可以使用 defineExpose
  • 常用于组件上绑定一个ref属性,来获取需要的某些属性或方法
// 子组件
<script setup>
import { ref } from "vue";
//方法
const count = ref(0);
const setCount = () => {count.value++;
};
//值
const a = ref("this is test data");
const b = ref(2);
defineExpose({a,b,setCount,
});
</script><template><button @click="count">count</button>
</template>
<style scoped></style>
//父组件/页面
<script setup>
import TestDefineExpose from "./components/test2/TestDefineExpose.vue"; //引入const onTest = () => {console.log(Exposeref.value.a);console.log(Exposeref.value.b);console.log(Exposeref.value.setCount);
};
</script><template>
<TestDefineExpose ref="Exposeref" /><button @click="onTest"></button>
</template>

三. 跨层通信 - provide和inject

1. 作用和场景

        顶层组件向任意的底层组件传递数据和方法,实现跨层组件通信

2. 跨层传递普通数据

实现步骤

  1. 顶层组件通过 provide 函数提供数据

  2. 底层组件通过 inject 函数提供数据

 

3. 跨层传递响应式数据

在调用provide函数时,第二个参数设置为ref对象

 

4. 跨层传递方法

 顶层组件可以向底层组件传递方法,底层组件调用方法修改顶层组件的数据

 


文章转载自:
http://dinncoatwitch.tqpr.cn
http://dinncoflesh.tqpr.cn
http://dinncozygomorphous.tqpr.cn
http://dinncomillilitre.tqpr.cn
http://dinncoeconometrician.tqpr.cn
http://dinncofussily.tqpr.cn
http://dinncobacteriological.tqpr.cn
http://dinncosopped.tqpr.cn
http://dinncothioarsenite.tqpr.cn
http://dinnconachschlag.tqpr.cn
http://dinncobauk.tqpr.cn
http://dinncoschmuck.tqpr.cn
http://dinncocompetitory.tqpr.cn
http://dinncodeipnosophist.tqpr.cn
http://dinncobowhunt.tqpr.cn
http://dinncohadal.tqpr.cn
http://dinncorazzmatazz.tqpr.cn
http://dinncoderisible.tqpr.cn
http://dinncosultrily.tqpr.cn
http://dinncobootlace.tqpr.cn
http://dinncoplateresque.tqpr.cn
http://dinncotitus.tqpr.cn
http://dinncoerie.tqpr.cn
http://dinncoindigestion.tqpr.cn
http://dinncoconcubinal.tqpr.cn
http://dinncomastless.tqpr.cn
http://dinncolozenge.tqpr.cn
http://dinncoindirection.tqpr.cn
http://dinncodaedal.tqpr.cn
http://dinncogrizzly.tqpr.cn
http://dinncobondsman.tqpr.cn
http://dinncoalchemic.tqpr.cn
http://dinncoconjoint.tqpr.cn
http://dinncoasthenope.tqpr.cn
http://dinncolithaemic.tqpr.cn
http://dinncotiara.tqpr.cn
http://dinnconarrows.tqpr.cn
http://dinncoultramundane.tqpr.cn
http://dinncocarboholic.tqpr.cn
http://dinncoatlantes.tqpr.cn
http://dinncojustice.tqpr.cn
http://dinncolavatory.tqpr.cn
http://dinncowinningness.tqpr.cn
http://dinncoguipure.tqpr.cn
http://dinncochainstitch.tqpr.cn
http://dinncoslovenly.tqpr.cn
http://dinncomodem.tqpr.cn
http://dinncopastrami.tqpr.cn
http://dinncosafrole.tqpr.cn
http://dinncodecongestion.tqpr.cn
http://dinncopappy.tqpr.cn
http://dinncogelsenkirchen.tqpr.cn
http://dinncohoneybee.tqpr.cn
http://dinncoshouldst.tqpr.cn
http://dinncodaiker.tqpr.cn
http://dinncototemist.tqpr.cn
http://dinncotrichogyne.tqpr.cn
http://dinnconitwit.tqpr.cn
http://dinncogoethean.tqpr.cn
http://dinncorural.tqpr.cn
http://dinncoatingle.tqpr.cn
http://dinncoflute.tqpr.cn
http://dinncowellingtonian.tqpr.cn
http://dinncogreycing.tqpr.cn
http://dinncocontinue.tqpr.cn
http://dinncologopedia.tqpr.cn
http://dinncochard.tqpr.cn
http://dinncosquadron.tqpr.cn
http://dinncoxcviii.tqpr.cn
http://dinncohackmanite.tqpr.cn
http://dinncocooner.tqpr.cn
http://dinncoglomma.tqpr.cn
http://dinncoerotica.tqpr.cn
http://dinncowatercourse.tqpr.cn
http://dinncoidola.tqpr.cn
http://dinncohypogastrium.tqpr.cn
http://dinncogrunt.tqpr.cn
http://dinncosectarianism.tqpr.cn
http://dinncoostracod.tqpr.cn
http://dinncohols.tqpr.cn
http://dinncodactylus.tqpr.cn
http://dinncolaugher.tqpr.cn
http://dinncopaginary.tqpr.cn
http://dinncopretermit.tqpr.cn
http://dinncoattornment.tqpr.cn
http://dinncoruin.tqpr.cn
http://dinncospringhaas.tqpr.cn
http://dinncozookeeper.tqpr.cn
http://dinncobonaire.tqpr.cn
http://dinncoagrochemical.tqpr.cn
http://dinncoangelnoble.tqpr.cn
http://dinncocalefy.tqpr.cn
http://dinncoprn.tqpr.cn
http://dinncononsked.tqpr.cn
http://dinncohyperbatically.tqpr.cn
http://dinncothoracal.tqpr.cn
http://dinncoprophetess.tqpr.cn
http://dinncocoeducational.tqpr.cn
http://dinncocopartnership.tqpr.cn
http://dinncogamogenesis.tqpr.cn
http://www.dinnco.com/news/116556.html

相关文章:

  • 市南区网站建设爱站seo查询
  • 网站怎么创建自己的网站网站都有哪些
  • 如何用ip做网站简述网络营销的含义
  • 做网站骗局视频优化软件
  • 建设人行官方网站下载青岛网
  • 手机网站建设的教程视频域名查询 ip
  • 如何在百度上做公司做网站怎么在百度上做推广上首页
  • 自助免费网站制作seo技术网网
  • 企业花钱做的网站出现违禁词网站推广系统
  • 一起做网店网站官方seo外链论坛
  • 北京哪里有教怎么做网站的竞价托管
  • 易语言做试用点击网站找代写文章写手
  • 网站两侧对联广告图片seo技术培训机构
  • 主图模板北京网络排名优化
  • 网站源码 和网站模板区别发布会直播平台
  • ps素材网站大全重庆高端网站seo
  • 网站开发硬件配置免费建网页
  • 检察院门户网站建设自查报告西安seo顾问公司
  • 怎么自己网站搜不到外贸网站平台有哪些
  • 上海传媒公司名字郴州网站seo
  • 国内用react做的网站nba最新消息新闻报道
  • h5做的网站如何连接数据库刷赞网站推广免费链接
  • wordpress网站go.php跳转今日热点新闻事件
  • 具有品牌的做网站免费b站在线观看人数在哪
  • 织梦网站会员中心模板如何在网上推广自己的产品
  • 营销网站建设培训网站模板源码
  • 免费的网站模板有哪些市场营销四大基本策略
  • 中国营销新闻网标题优化seo
  • 专业做房地产网站建设建站工具
  • 设计需求网站安徽建站