A common scenario is to present different components based on the state of the application. Dynamic components in Vue make this simple by providing a component element that simply needs to be bound to the component that you want to render. This example shows using a select dropdown in Vue to select the component to render.

<template>
<Settings>
<Layout slot-scope="{header, footer}">
<AwesomeHeader slot="header" :header="header"></AwesomeHeader>
<div slot="content" class="flex-grow">
<select v-model="selectedComp">
<option v-for="comp in comps" :key="comp.name" :value="comp">{{comp.name}}</option>
</select>
<component :is="selectedComp"></component>
</div>
<AwesomeFooter slot="footer" :footer="footer"></AwesomeFooter>
</Layout>
</Settings>
</template> <script>
import Vue from "vue"
import { Component, Prop } from "vue-property-decorator"
import Settings from "./Settings"
import Layout from "./Layout"
import { Header, Footer } from "./components" const One = {
functional: true,
name: "One",
render: h => <h1 class="bg-red">One</h1>
} const Two = {
functional: true,
name: "Two",
render: h => <h1 class="bg-green">Two</h1>
} const Three = {
functional: true,
name: "Three",
render: h => <h1 class="bg-purple">Three</h1>
} @Component({
components: {
Settings,
Layout,
AwesomeHeader: Header,
AwesomeFooter: Footer
}
})
export default class App extends Vue {
comps = [One, Two, Three]
selectedComp = this.comps[0]
}
</script>

最新文章

  1. 《阿Q正传》读后感
  2. 五、HTML判断输入长度,体会字体颜色变化
  3. selenium源码分析-webdriver(二)
  4. 在UIScrollView的delegate方法判断滚动快慢
  5. 【C解毒】滥用变量
  6. JMS学习(一)基本概念
  7. php总结 --- 19. 其他小知识
  8. 认识ASP.NET MVC6
  9. 配置pyqt5环境 for python3.4 on Linux Mint 17.1
  10. div+css与table布局
  11. dos2unix(windows脚本文件放到unix下运行要注意)
  12. scp传输提示bash: scp: command not found
  13. python面向对象之继承/多态/封装
  14. mysql 开启root外部链接权限
  15. Scala并发编程【进阶】
  16. xadmin集成DjangoUeditor
  17. My SQL随记 001 常用名词/结构化语言
  18. EasyWeChat使用(laravel框架下)
  19. Linux系统下CPU使用(load average)梳理
  20. Android:TextView控件

热门文章

  1. .Net MVC之间的关系以及如何运用
  2. HTML5 WEB Storage - localStorage存储位置在哪
  3. LN : Eden Bitset_3
  4. Android开发笔记(2)——ViewGroup
  5. UVM基础之------uvm_port_base
  6. sqlserver如何查询一个表的主键都是哪些表的外键
  7. sp_Msforeachtable与sp_Msforeachdb详解
  8. 字符集编码---3 Windows BOM
  9. 【sqli-labs】 less62 GET -Challenge -Blind -130 queries allowed -Variation1 (GET型 挑战 盲注 只允许130次查询 变化1)
  10. HDU_2476_String painter_(区间dp)