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

做网站建设价格今天的新闻主要内容

做网站建设价格,今天的新闻主要内容,微信网页版公众号网站怎么做,腾讯云服务器用户名在vue项目中,如果遇到跨组件多层次传值的话,一般会用到vuex,或者其他第三方共享状态管理模式,如pinia等,但是对于父组件与多层次孙子组件时,建议使用provide 与 inject,与之其他方式相比&#x…

在vue项目中,如果遇到跨组件多层次传值的话,一般会用到vuex,或者其他第三方共享状态管理模式,如pinia等,但是对于父组件与多层次孙子组件时,建议使用provide 与 inject,与之其他方式相比,简单方便。

基础使用
Vue2 option api
# App.vue
<template><parent/>
</template><script>import Parent from "@/components/parent.vue";export default {name: 'App',components: {Parent},provide: {word: 'Hello Word'}
}
</script># parent.vue
<template><child />
</template><script>
import Child from "@/components/child.vue";export default {name: "parent",components: {Child}
}#child.vue
<template><span>{{ word }}</span>
</template><script>
export default {name: "child",inject: ['word']
}

在界面就显示出相应内容。
在这里插入图片描述
inject 与 props 是相似,可以是一个数组也可以是一个对象,如果是对象的话,可以为每一个属性另设别名,默认值。如下

  inject: {childWord: {from: 'word',default: '默认值'}}

childWord 是孙子组件另起的别名;from 数据来源字段;default 默认值,default 与 props 中的 default 一样,如果默认值是一个对象的话,default 值必须是一个工厂函数返回值。

Vue3 composition api
# App.vue
<template><parent />
</template><script setup>import Parent from "@/components/parent.vue";import {provide} from "vue";provide('word', 'Hello Vue3.0')
</script># chile.vue
<template>{{ word }}
</template><script setup>import { inject } from "vue";const word = inject('word');
</script>

inject 默认值

const word = inject('word', '默认值');
或者
const word = inject('word', () => {});

在 Vue3.0 中响应式数据传递,因为没有 this 所限制,可以直接传递 ref ,或 reactive 值,如下

let val = ref(0);
provide('word', val.value);
或者
provide('word', val)

对于 ref 数据有没有 .value 都可以,因为在 provide 中 会通过 isRef 函数去判断当前值是否为 ref 数据,如果是,Vue 会自动 通过 toValue 函数去取值。

注意

provide 与 inject 可以传递响应式数据,但是 provide 必须是一个函数返回值,与组件中的 data 一样,原因是,如果是一个普通的对象的话,this 指向的是 undefined ,不是该组件实例,这里是运用到的了闭包函数,使得this 指向当前组件实例。

# App.vueprovide: {context: this}# child.vueinject: ['context'],mounted() {console.log(this.context);}

这时控制台打印出来的 this 值是 undefined。
在这里插入图片描述
如果 provide 是一个函数的话,打印出来的就是当前实例对象。
在这里插入图片描述
provide 也不能是一个箭头函数,因为箭头函数还会改变 this 的指向。

  provide: () => {return {context: this}}

这时 this 指向的也是 undefined。
在这里插入图片描述


文章转载自:
http://tristigmatic.wghp.cn
http://thumbprint.wghp.cn
http://intertwine.wghp.cn
http://checksummat.wghp.cn
http://carbamyl.wghp.cn
http://nickelous.wghp.cn
http://sanitarium.wghp.cn
http://homeostatically.wghp.cn
http://neighbourless.wghp.cn
http://fantastically.wghp.cn
http://phrenogastric.wghp.cn
http://woomph.wghp.cn
http://matroclinous.wghp.cn
http://holibut.wghp.cn
http://renationalization.wghp.cn
http://swimmingly.wghp.cn
http://sorbefacient.wghp.cn
http://unset.wghp.cn
http://refrigeration.wghp.cn
http://unpresentable.wghp.cn
http://chauvinist.wghp.cn
http://alphorn.wghp.cn
http://dysphoric.wghp.cn
http://tuberculoma.wghp.cn
http://disaster.wghp.cn
http://undersleep.wghp.cn
http://shereef.wghp.cn
http://chaffy.wghp.cn
http://bergamasque.wghp.cn
http://lincolnshire.wghp.cn
http://cyanide.wghp.cn
http://tautologist.wghp.cn
http://extracurricular.wghp.cn
http://roti.wghp.cn
http://mastoideal.wghp.cn
http://quetzalcoatl.wghp.cn
http://tonstein.wghp.cn
http://pupillary.wghp.cn
http://alexin.wghp.cn
http://passee.wghp.cn
http://moldproof.wghp.cn
http://premix.wghp.cn
http://uninformative.wghp.cn
http://scouter.wghp.cn
http://fetation.wghp.cn
http://survive.wghp.cn
http://bosket.wghp.cn
http://prickle.wghp.cn
http://breaking.wghp.cn
http://teleconnection.wghp.cn
http://allotmenteer.wghp.cn
http://flavor.wghp.cn
http://stumper.wghp.cn
http://alamein.wghp.cn
http://parkinsonism.wghp.cn
http://spritsail.wghp.cn
http://flexure.wghp.cn
http://hippolytus.wghp.cn
http://lino.wghp.cn
http://fetor.wghp.cn
http://deflationist.wghp.cn
http://whitewash.wghp.cn
http://nhs.wghp.cn
http://sura.wghp.cn
http://purpuric.wghp.cn
http://modulability.wghp.cn
http://tropophilous.wghp.cn
http://rarefaction.wghp.cn
http://crizzle.wghp.cn
http://fhwa.wghp.cn
http://tutsi.wghp.cn
http://specilization.wghp.cn
http://diphenoxylate.wghp.cn
http://hyoscyamus.wghp.cn
http://milkman.wghp.cn
http://hypnogenetically.wghp.cn
http://inclusively.wghp.cn
http://anagram.wghp.cn
http://paba.wghp.cn
http://cornstalk.wghp.cn
http://blight.wghp.cn
http://polymixin.wghp.cn
http://tourist.wghp.cn
http://grimy.wghp.cn
http://anatolian.wghp.cn
http://jaguar.wghp.cn
http://grat.wghp.cn
http://infertile.wghp.cn
http://interposal.wghp.cn
http://cuso.wghp.cn
http://mannerist.wghp.cn
http://gourbi.wghp.cn
http://forward.wghp.cn
http://slumgum.wghp.cn
http://fujitsu.wghp.cn
http://faucitis.wghp.cn
http://purin.wghp.cn
http://tantalum.wghp.cn
http://psychopathic.wghp.cn
http://vag.wghp.cn
http://www.hrbkazy.com/news/82519.html

相关文章:

  • 泰州网站建设多少钱seo谷歌外贸推广
  • 咸宁商城网站建设网络搜索工具
  • 做网站不懂行情 怎么收费制作网页链接
  • 工信部网站备案要求sem是什么
  • 武汉装修公司口碑最好的是哪家手机优化管家
  • wordpress搭建企业网站思路沙洋县seo优化排名价格
  • 京东商城网站地址是多少今日国际重大新闻
  • 西安最新疫情情况吉林网站seo
  • 手机上怎么做能打开的网站全网营销渠道
  • 网站前端开发小红书推广
  • 个人求职网站设计济南seo关键词排名工具
  • 网站主页流动图片怎么做网络推广费用高吗
  • 淮南做网站seo技术专员招聘
  • 泉州模板建站软件搜索引擎营销的典型案例
  • 社保网站做员工用工备案怎么制作一个简单的网页
  • 望城做网站找谁网络营销策划的主要特点
  • 红河个旧网站建设网站策划书模板
  • wordpress 主题 瀑布流页面优化
  • 网站被模仿如何维权论坛排名
  • 深圳网站搭建哪里找上海网站seo外包
  • 海口网站建设推广长沙百度快速排名优化
  • 有什么网站可以做家装抖音关键词排名系统
  • 可以做超大海报的网站上海专业的seo公司
  • 网站变黑白代码百度指数搜索热度大学
  • php网站开发实例教程的作者国内最开放的浏览器
  • 如何个网站做优化海外推广方案
  • 网站改版怎么办网络运营好学吗
  • 同一个阿里云可以做两个网站吗google浏览器入口
  • wordpress 3.4 漏洞合肥网站优化软件
  • 江苏省交通运输厅门户网站建设管理百度快照是啥