组件通信 Provideinject
生活随笔
收集整理的這篇文章主要介紹了
组件通信 Provideinject
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在父組件中利用Provide 注入數(shù)據(jù),在所有的子組件都可以拿到這個(gè)數(shù)據(jù) 可以在vue 中用來刷新頁面
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Provide&&Inject通信</title><script src="./node_modules/vue/dist/vue.js"></script> </head> <body><div id="app"><my-button><my></my></my-button></div> </body> <script>Vue.component('my-button',{template:`<div><slot></slot></div>`,//在父組件注入數(shù)據(jù) provide:{msg:'hello'}})//所有的子組件都可以拿到數(shù)據(jù)Vue.component('my',{template:`<div>{{msg}}</div>`,inject:['msg']})let vm = new Vue({el:'#app'})//hello </script> </html>輸出:
?
轉(zhuǎn)載于:https://www.cnblogs.com/guangzhou11/p/11539752.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的组件通信 Provideinject的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: layui token 过期 重新登陆
- 下一篇: 组件通信 $ref