When the array changes, dynamically load the corresponding data Scenario : Click on different component names and the interface will display the corresponding components Step 1 : Import required components Step 2 : Click the tab and add the corresponding component name into the array Step 3 : Use dynamic components and bind the :is attribute to the component name <div v-for="(item, index) in componentData" :key="index"> <components :is="item.componentName"/> </div> Example : Monitoring property changes in an object, deep monitoring <!-- DynamicComponent.vue --> <template> <section> <div v-for="(item, index) in componentData" :key="index"> <components :is='item.componentName' :params="item.content" /> </div> </section> </template> <script> import PageOne from './pageComponents/PageOne' import PageTwo from './pageComponents/PageTwo' import PageThree from './pageComponents/PageThree' export default{ name: 'DynamicComponent', components: PageOne, PageTwo, PageThree }, data () { return { componentData: [ { componentName: 'PageOne', content: { title: 'Title 1' } }, { componentName: 'PageTwo', content: { title: 'Title 2' } } ] } } } </script> <!-- PageOne --> <template> <section> {{content}} </section> </template> <script> export default{ name: 'PageOne', props: { params: { type: Object, default: function(){ return {} } } }, data () { return { content: this.params.title } }, watch: params: { handler(newVal, oldVal){ this.content = newVal.title }, deep: true, immediate: true } } } </script> <!-- PageTwo --> <template> <section> {{content}} </section> </template> <script> export default{ name: 'PageTwo', props: { params: { type: Object, default: function(){ return {} } } }, data () { return { content: this.params.title } }, watch: params: { handler(newVal, oldVal){ this.content = newVal.title }, deep: true, immediate: true } } } </script> SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! When the array changes, dynamically load the corresponding data Scenario : Click on different component names and the interface will display the corresponding components Step 1 : Import required components Step 2 : Click the tab and add the corresponding component name into the array Step 3 : Use dynamic components and bind the :is attribute to the component name <div v-for="(item, index) in componentData" :key="index"> <components :is="item.componentName"/> </div> Example : Monitoring property changes in an object, deep monitoring <!-- DynamicComponent.vue --> <template> <section> <div v-for="(item, index) in componentData" :key="index"> <components :is='item.componentName' :params="item.content" /> </div> </section> </template> <script> import PageOne from './pageComponents/PageOne' import PageTwo from './pageComponents/PageTwo' import PageThree from './pageComponents/PageThree' export default{ name: 'DynamicComponent', components: PageOne, PageTwo, PageThree }, data () { return { componentData: [ { componentName: 'PageOne', content: { title: 'Title 1' } }, { componentName: 'PageTwo', content: { title: 'Title 2' } } ] } } } </script> <!-- PageOne --> <template> <section> {{content}} </section> </template> <script> export default{ name: 'PageOne', props: { params: { type: Object, default: function(){ return {} } } }, data () { return { content: this.params.title } }, watch: params: { handler(newVal, oldVal){ this.content = newVal.title }, deep: true, immediate: true } } } </script> <!-- PageTwo --> <template> <section> {{content}} </section> </template> <script> export default{ name: 'PageTwo', props: { params: { type: Object, default: function(){ return {} } } }, data () { return { content: this.params.title } }, watch: params: { handler(newVal, oldVal){ this.content = newVal.title }, deep: true, immediate: true } } } </script> SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Detailed explanation of MySQL EXPLAIN output columns
>>: About Jenkins + Docker + ASP.NET Core automated deployment issues (avoid pitfalls)
Aggregating data from various sources allows the ...
This article example shares the specific code of ...
The MySQL server is running with the --skip-grant...
This article example shares the specific code of ...
Primitive values -> primitive types Number S...
Source code (some classes deleted): Copy code The ...
One of the most commonly used and discussed data ...
Preface This article introduces the fifth questio...
Table of contents Primary key index Create indexe...
I encountered mysql ERROR 1045 and spent a long t...
Table of contents Character Set Comparison Rules ...
Sometimes we want to execute a command in a conta...
Uninstall the installed version on Ubuntu: sudo a...
1. Dynamic query rules The dynamic query rules ar...
Preface var is a way to declare variables in ES5....