VUE dynamic component instance analysis

Let multiple components use the same mount point and dynamically switch, which is a dynamic component. The VUE dynamic component


is dynamically bind to it by using the retained

element. IS features, dynamic components

  switch page 
var home = { Template: '
I am home page '}; var post = {template: '
I am submitting page
'}; var archive = {template: '
I am archive page
'}; New Vue ({EL:' #Example ', Components: {Home, Post, Archive,}, Data: {Index: 0, Arch: [' Home ',' Post ',' Archive '], }, computed: {currentview () {return this.arr [this.index];}}, methods: {change () {this.index = (++ this.index)% 3;}}})

switched page
  
I am home page `}, {template: ` I am a submission page
`}, {template: ` I am archive page
`}],}, computed: {currentview () {return this.arr [this.index];}}, methods: {change () {this.index = (++ this.index)% 3;}}}
Cache
When the dynamic component is wrapped, the unacceptable component instance is cached. Not to destroy them. Similar to
,

is an abstract component: it does not render a DOM element, nor does it appear in the parent component chain
[Basic usage]

Switching page

 New Vue ({EL: '#example', DATA: { INDEX: 0, Arr: [{Template: ` I am home page 
`}, {template: ``}, {template: ` I am archive Page `}],}, computed: {crurn this.arr [this.index];}}, methods: {change () {let len ​​= this.arr.length; tHis.index = (++ this.index)% LEN;}}})
[Condition judgment]
If there are multiple Conditional child elements,
requires only one child element to be rendered
Switching page

New Vue ({EL: ‘#example’, Components: {Home: {Template: `

I am a homepage `}: {template:`

I am a submission page
`}, archive: {template:` I am archive page
 `},}, data: {index: 0,}, methods: {changing () {let len ​​= Object.keys (this. $ Options.components) .length; this.index = (++ this.index)% Len;}}})  
ActiVated and Deactivated Trigger in all nested components in tree
{msg}}
New Vue ({ El: ‘#eXample ‘, Data: {INDEX: 0, MSG:’, Arr: [{Template: `

I am home page

`, Activated () {this. $ EMIT (‘pass-data’, ‘home page Added ‘);}, deactivated () {this. $ EMIT (‘ pass-data ‘,’ home page is removed “);},}, {template:`

I am submitting page `} , {Template: `

I am archive page
`}],}, computed: {currentview () {return this.arr [this.index];}}, methods: {change () {var LEN = this.arr.length; this.index = (++ this.index)% Len;}, getdata (value) {this.msg = value; settimeout (() => {this.msg = ‘;}, 500)}}})
  

Match First Check the Name option of the component itself, if the Name option is not available, match its local registration name (key value of the parent component components option). Anonymous components cannot be matched

     above Represents only HOME and Archive, does not cache Posts     Switching page       New Vue ({EL: '#Example', Data: {Index: 0, Arr: [{name: 'Home', Template: ` I am home page  `}, {name:` ​​`, Template:` 
I am a submission page `}, {name: ‘archive’, template:`
I am archived page

`}] ,}, computew () {Return this.arr [this.index];}}, methods: {change () {var len = this.arr.Length; this.index = (++ this.index) % Len;},}}

 Summary    The above is the Vue introduced to you. Dynamic component instance analysis, I hope to help everyone, if you have any questions, pleaseI leave a message, the small package will reply to everyone in time!                      
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment