vue动态组件加载

1.html

  <component :is="currentView" ></component>

2.js

Vue.component("child1", {
	template: '<p>hell child1</p>'
})
Vue.component("child2", {
	template: '<p>hell child2</p>'
})
new Vue({
	el: '#root',
  data: {
		currentView: 'child1',
    active: 0,
    tabs: [
    	{
      	type: 'child1 tab',
        view: 'child1'
      },{
      	type: 'child2 tab',
        view: 'child2'
      }
    ]
	},
  methods: {
  	toggle(i,v) {
      this.active = i
			this.currentView = v
		}
  }
})

参考:https://jsfiddle.net/2kn4hqts/


猜你喜欢

转载自blog.csdn.net/milli236/article/details/80522231