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)
To back up multiple databases, you can use the fo...
Preface The count function is used to count the r...
This article introduces how to install Chrome bro...
This article shares the specific code of Vue to i...
Table of contents Require Implementation Code dat...
The title images on Zhihu Discovery columns are g...
Docker only maps ports to IPv6 but not to IPv4 St...
This article shares the installation and configur...
Table of contents Preface 1. Preparation 2. Insta...
The first time I wrote a MySQL FUNCTION, I kept g...
Table of contents View all storage engines InnoDB...
Table of contents HTTP hijacking, DNS hijacking a...
Stored Functions What is a stored function: It en...
[Who is nslookup?] 】 The nslookup command is a ve...
The following content introduces the process and ...