vue2.0 非父子组件(爷孙传参) 注:不是响应式的

编程入门 行业动态 更新时间:2024-10-07 16:19:02

vue2.0 非<a href=https://www.elefans.com/category/jswz/34/1768972.html style=父子组件(爷孙传参) 注:不是响应式的"/>

vue2.0 非父子组件(爷孙传参) 注:不是响应式的

爷爷组件

<template>
{{title}}<button @click="setTitle">改变title</button><br><Son />
</template><script>
import Son from "./components/Son"
export default {components:{Son},//下面两种方式 要是穿对象的话就得用return的方式        // provide:{//   title:title,//   userInfo:{//     name:"张三",//     age:40//   }// },provide(){return{title:this.title,userInfo:{name:"张三",age:40}}},methods:{setTitle(){this.title = "修改后的Title"console.log(this.title)}}}
</script><style></style>

父组件

<template><Grandson />
</template><script>
import Grandson from "./Grandson"
export default {components:{Grandson}}
</script><style></style>

孙子组件

<template>孙子 {{title}}<br/>{{userInfo}}
</template><script>
export default {inject:["title","userInfo"]}
</script><style></style>

更多推荐

vue2.0 非父子组件(爷孙传参) 注:不是响应式的

本文发布于:2024-02-28 09:33:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1769150.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:父子   组件   爷孙传参

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!