[Vue @Component] Switch Between Vue Components with Dynamic Components
2024-08-25 09:28:29
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>
最新文章
- 《阿Q正传》读后感
- 五、HTML判断输入长度,体会字体颜色变化
- selenium源码分析-webdriver(二)
- 在UIScrollView的delegate方法判断滚动快慢
- 【C解毒】滥用变量
- JMS学习(一)基本概念
- php总结 --- 19. 其他小知识
- 认识ASP.NET MVC6
- 配置pyqt5环境 for python3.4 on Linux Mint 17.1
- div+css与table布局
- dos2unix(windows脚本文件放到unix下运行要注意)
- scp传输提示bash: scp: command not found
- python面向对象之继承/多态/封装
- mysql 开启root外部链接权限
- Scala并发编程【进阶】
- xadmin集成DjangoUeditor
- My SQL随记 001 常用名词/结构化语言
- EasyWeChat使用(laravel框架下)
- Linux系统下CPU使用(load average)梳理
- Android:TextView控件
热门文章
- .Net MVC之间的关系以及如何运用
- HTML5 WEB Storage - localStorage存储位置在哪
- LN : Eden Bitset_3
- Android开发笔记(2)——ViewGroup
- UVM基础之------uvm_port_base
- sqlserver如何查询一个表的主键都是哪些表的外键
- sp_Msforeachtable与sp_Msforeachdb详解
- 字符集编码---3 Windows BOM
- 【sqli-labs】 less62 GET -Challenge -Blind -130 queries allowed -Variation1 (GET型 挑战 盲注 只允许130次查询 变化1)
- HDU_2476_String painter_(区间dp)