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

网站如何做服务器授权书seo规范培训

网站如何做服务器授权书,seo规范培训,网络规划与设计案例,长沙市委宣传部组件通信 一.$attrs(祖>孙间接)二、$refs()父>子, $parent()子>父三.provide,inject(祖>孙直接)四.pinia五.slot1.默认插槽2.具名插槽3.作用域插槽 一.$attrs(祖>孙间接) $attrs用于实现当前组件的父组…

组件通信

  • 一.$attrs(祖=>孙间接)
  • 二、$refs()父=>子, $parent()子=>父
  • 三.provide,inject(祖=>孙直接)
  • 四.pinia
  • 五.slot
    • 1.默认插槽
    • 2.具名插槽
    • 3.作用域插槽

一.$attrs(祖=>孙间接)

$attrs用于实现当前组件的父组件,向当前组件的子组件通信(祖→孙)。
$ attrs是一个对象,包含所有父组件传入的标签属性。
注意:$attrs会自动排除props中声明的属性(可以认为声明过的 props 被子组件自己“消费”了)
和props用法差不多
父组件

<template><div class="father"><h3>父组件</h3><Child :a="a" :b="b" :c="c" :d="d" v-bind="{x:100,y:200}" :updateA="updateA"/></div>
</template><script setup lang="ts" name="Father">import Child from './Child.vue'import { ref } from "vue";let a = ref(1)let b = ref(2)let c = ref(3)let d = ref(4)function updateA(value){a.value = value}
</script>

子组件:

<template><div class="child"><h3>子组件</h3><GrandChild v-bind="$attrs"/></div>
</template><script setup lang="ts" name="Child">import GrandChild from './GrandChild.vue'
</script>

孙组件

<template><div class="child"><h3>子组件</h3><GrandChild v-bind="$attrs"/></div>
</template><script setup lang="ts" name="Child">import GrandChild from './GrandChild.vue'
</script>

二、$refs()父=>子, $parent()子=>父

$ refs父亲拿取孩子的数据,$parent孩子拿取父亲的数据
1.原理
$refs:值为对象,包含所有被ref属性标识的DOM元素或组件实例。
$parent:值为对象,当前组件的父组件实例对象。
2.传递数据的需要把数据暴露出来才能被用
用defineExpose()暴露

// 宏函数把数据交给外部
defineExpose({ toy, book })

父组件

<template><div class="father"><h3>父组件</h3><h4>房产:{{ house }}</h4><button @click="changeToy">修改Child1的玩具</button><button @click="getAllChild($refs)">让所有孩子的书变多</button><Child1 ref="c1"/></div>
</template><script setup lang="ts" name="Father">import Child1 from './Child1.vue'import { ref,reactive } from "vue";let c1 = ref()// 数据let house = ref(4)// 方法function changeToy(){c1.value.toy = '小猪佩奇'}function getAllChild(refs:{[key:string]:any}){console.log(refs)for (let key in refs){refs[key].book += 3}}// 向外部提供数据defineExpose({house})
</script>

子组件

<template><div class="child1"><h3>子组件1</h3><h4>玩具:{{ toy }}</h4><h4>书籍:{{ book }}</h4><button @click="minusHouse($parent)">干掉父亲的一套房产</button></div>
</template><script setup lang="ts" name="Child1">import { ref } from "vue";// 数据let toy = ref('奥特曼')let book = ref(3)// 方法function minusHouse(parent:any){parent.house -= 1}// 把数据交给外部defineExpose({toy,book})</script>

三.provide,inject(祖=>孙直接)

具体使用:
在祖先组件中通过provide配置向后代组件提供数据
在后代组件中通过inject配置来声明接收数据
祖组件:

<template><div class="father"><h3>父组件</h3><h4>资产:{{ money }}</h4><h4>汽车:{{ car }}</h4><button @click="money += 1">资产+1</button><button @click="car.price += 1">汽车价格+1</button><Child/></div>
</template><script setup lang="ts" name="Father">import Child from './Child.vue'import { ref,reactive,provide } from "vue";// 数据let money = ref(100)let car = reactive({brand:'奔驰',price:100})// 用于更新money的方法function updateMoney(value:number){money.value += value}// 提供数据provide('moneyContext',{money,updateMoney})provide('car',car)
</script>

孙组件:

<template><div class="grand-child"><h3>我是孙组件</h3><h4>资产:{{ money }}</h4><h4>汽车:{{ car }}</h4><button @click="updateMoney(6)">点我</button></div>
</template><script setup lang="ts" name="GrandChild">import { inject } from 'vue';// 注入数据let {money,updateMoney} = inject('moneyContext',{money:0,updateMoney:(x:number)=>{}})let car = inject('car')
</script>

四.pinia

参考之前的笔记

五.slot

1.默认插槽

父组件中:<Category title="今日热门游戏"><ul><li v-for="g in games" :key="g.id">{{ g.name }}</li></ul></Category>
子组件中:<template><div class="item"><h3>{{ title }}</h3><!-- 默认插槽 --><slot></slot></div></template>

2.具名插槽

父组件中:<Category title="今日热门游戏"><template v-slot:s1><ul><li v-for="g in games" :key="g.id">{{ g.name }}</li></ul></template><template #s2><a href="">更多</a></template></Category>
子组件中:<template><div class="item"><h3>{{ title }}</h3><slot name="s1"></slot><slot name="s2"></slot></div></template>

3.作用域插槽

数据在组件的自身(子组件),但根据数据生成的结构需要组件的使用者(父组件)来决定。(新闻数据在News组件中,但使用数据所遍历出来的结构由App组件决定)

父组件中:<Game v-slot="params"><!-- <Game v-slot:default="params"> --><!-- <Game #default="params"> --><ul><li v-for="g in params.games" :key="g.id">{{ g.name }}</li></ul></Game>子组件中:<template><div class="category"><h2>今日游戏榜单</h2><slot :games="games" a="哈哈"></slot></div></template><script setup lang="ts" name="Category">import {reactive} from 'vue'let games = reactive([{id:'asgdytsa01',name:'英雄联盟'},{id:'asgdytsa02',name:'王者荣耀'},{id:'asgdytsa03',name:'红色警戒'},{id:'asgdytsa04',name:'斗罗大陆'}])</script>
http://www.fp688.cn/news/161201.html

相关文章:

  • 贵阳免费网站建设百度关键词推广价格
  • wordpress ssl 设置seo托管服务
  • 网站访问速度检测如何优化网站首页
  • 网站底部的备案信息文登seo排名
  • 上海加盟网网站建设会员制营销
  • javascript作品网站网站制作公司排行榜
  • 刘涛做的儿童购物网站网络推广平台公司
  • 邢台专业做网站哪家好全网营销老婆第一人
  • 3733手游网站在哪里做的win7优化教程
  • 上海公司注册代理记账seo网站推广助理招聘
  • 做零食的网站网络营销专业是干什么的
  • 做网站需要什么工具长春seo排名公司
  • 淘宝上做网站的靠谱吗廊坊seo排名
  • 扁平化网站后台seo网站排名优化教程
  • b2c电子网站建设代写软文费用全网天下实惠
  • 不参与网站建设的弊端百度app关键词优化
  • 上海品牌网站制作写软文用什么软件
  • 深圳住房和城乡建设局网站首页湖南优化推广
  • 旅游网站案例分析个人如何建立免费网站
  • 彩票投注网站怎样做app拉新推广平台渠道
  • 高端网站开发步骤自己怎么制作网页
  • 微网站官网信息流广告公司排名
  • 江苏省疫情防控最新文件福州seo顾问
  • 登录浏览器是建设银行移动门户网站百度广告推广价格
  • 聊城网站建设包括哪些seo流量排名工具
  • php微信微网站怎么做优化推广什么意思
  • 商城网站建设哪个公司好搜索引擎营销案例有哪些
  • 硅云买域名做网站推广产品的方法
  • 哪个网站专做民宿千度seo
  • 微商做网站女教师遭网课入侵视频大全