1. Explanation of provide and inject
2. Use of provide and inject
3. Parent Component <template> <erzi-com></erzi-com> </template> <script lang="ts"> import ErZi from "../components/ErZi.vue" import {provide, ref} from "vue" export default { name:"About", components:{ 'erzi-com':ErZi }, setup(){ let giveSunziData=ref({ with:100, height:50, bg:'pink' }) // The first parameter is the name of the shared data (giveSunzi) // The second parameter is the shared data (giveSunziData) provide('giveSunzi',giveSunziData) } } </script>
4. Son Component <template> <div> <h2>Son Components</h2> <div>Get value: {{getFaytherData}}</div> </div> <hr/> <sun-con></sun-con> </template> <script lang="ts"> import { defineComponent, inject } from 'vue'; import SunZI from "./SunZI.vue" export default defineComponent({ name: 'ErZi', components:{ 'sun-con':SunZI }, setup(){ let getFaytherData = inject('giveSunzi'); return { getFaytherData } } }); </script> 5. Grandchild Component <template> <div> <h2>Grandchild components</h2> <div>The value obtained is {{getYeYeData}}</div> </div> </template> <script lang="ts"> import { defineComponent,inject } from 'vue'; export default defineComponent({ setup(){ let getYeYeData=inject('giveSunzi'); return { getYeYeData } } }); </script> 6. Rendering 7. Can a parent component pass multiple rovides?
8. Reference scenarios of rovide and inject
This is the end of this article about the use of provide and inject in vue3. For more relevant content on the use of vue provide and inject, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of Tomcat directory structure
>>: MySQL 8.x msi version installation tutorial with pictures and text
Table of contents 1. props 2..sync 3.v-model 4.re...
Write configuration files in server.xml and conte...
1. Background Buttons are very commonly used, and...
Without further ado, let’s get started with resou...
Table of contents jQuery's $.ajax The beginni...
NC's full name is Netcat (Network Knife), and...
Due to the company's business requirements, t...
1.1 Copy the nginx installation package and insta...
Table of contents 1.setInterval() 2.setTimeout() ...
1. W3C versions of flex 2009 version Flag: displa...
Data Types and Operations Data Table 1.1 MySQL ty...
This article shares the specific code of JavaScri...
0. Preliminary preparation Disable secure boot in...
Software and hardware environment centos7.6.1810 ...
To beautify the table, you can set different bord...