在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
@Provide decorators in tandem!
When you want to provide some service or data from parent to child component you can use @Provide and @Inject.
Parent component: <template> <div class="hello"> <ChildComp :msg="'What a good day!'"/> </div> </template> <script lang="ts"> import Vue from 'vue' import {Component, Provide} from 'vue-property-decorator' import ChildComp from './Child.vue'; @Component({ }) export default class Hello extends Vue { @Provide('users') users = [ { name: 'test', id: 0 } ] } </script>
Child: <template> <div> {{users}} </div> </template> <script lang="ts"> import Vue from 'vue' import {Component, Inject} from 'vue-property-decorator' @Component({}) export default class Child extends Vue { message: string = "Hello"; @Inject('users') users; } </script>
|
请发表评论