inject metodo al posto di usare emits per propagare un evento
| | |
| | | :topic-title="activeTopic && activeTopic.title" |
| | | :text="activeTopic && activeTopic.fullText" |
| | | ></active-element> |
| | | <knowledge-base @select-topic="activateTopic"></knowledge-base> |
| | | <knowledge-base ></knowledge-base> |
| | | </div> |
| | | </template> |
| | | |
| | |
| | | }, |
| | | provide(){ |
| | | return { |
| | | topics: this.topics |
| | | topics: this.topics, |
| | | selectTopic: this.activateTopic, |
| | | } |
| | | }, |
| | | methods: { |
| | |
| | | <template> |
| | | <section> |
| | | <h2>Select a Topic</h2> |
| | | <knowledge-grid @select-topic="$emit('select-topic', $event)"></knowledge-grid> |
| | | <knowledge-grid ></knowledge-grid> |
| | | </section> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | |
| | | emits: ['select-topic'], |
| | | }; |
| | | </script> |
| | |
| | | <li> |
| | | <h3>{{ topicName }}</h3> |
| | | <p>{{ description }}</p> |
| | | <button @click="$emit('select-topic', id)">Learn More</button> |
| | | <button @click="selectTopic(id)">Learn More</button> |
| | | </li> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | inject: ['selectTopic'], |
| | | props: ['id', 'topicName', 'description'], |
| | | emits: ['select-topic'], |
| | | }; |
| | |
| | | :id="topic.id" |
| | | :topic-name="topic.title" |
| | | :description="topic.description" |
| | | @select-topic="$emit('select-topic', $event)" |
| | | ></knowledge-element> |
| | | </ul> |
| | | </template> |
| | |
| | | <script> |
| | | export default { |
| | | inject: ['topics'], |
| | | emits: ['select-topic'] |
| | | }; |
| | | </script> |