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>

[Vue @Component] Switch Between Vue Components with Dynamic Components的更多相关文章

  1. 前端框架vue.js系列(9):Vue.extend、Vue.component与new Vue

    前端框架vue.js系列(9):Vue.extend.Vue.component与new Vue 本文链接:https://blog.csdn.net/zeping891103/article/det ...

  2. Vue.mixin Vue.extend(Vue.component)的原理与区别

    1.本文将讲述 方法 Vue.extend Vue.mixin 与 new Vue({mixins:[], extend:{}})的区别与原理 先回顾一下 Vue.mixin 官网如下描述: Vue. ...

  3. vue component :is

    vue component :is Vue <component> element https://vuejs.org/v2/guide/components.html#Dynamic-C ...

  4. vue 快速入门 系列 —— vue 的基础应用(上)

    其他章节请看: vue 快速入门 系列 vue 的基础应用(上) Tip: vue 的基础应用分上下两篇,上篇是基础,下篇是应用. 在初步认识 vue一文中,我们已经写了一个 vue 的 hello- ...

  5. [Vue @Component] Dynamic Vue.js Components with the component element

    You can dynamically switch between components in a template by using the reserved <component>  ...

  6. vue & dynamic components

    vue & dynamic components https://vuejs.org/v2/guide/components-dynamic-async.html keep-alive htt ...

  7. [Vue @Component] Extend Vue Components in TypeScript

    This lesson shows how you can extend and reuse logic in Vue components using TypeScript inheritance. ...

  8. [Vue @Component] Pass Props Between Components with Vue Slot Scope & renderless component

    Components with slots can expose their data by passing it into the slot and exposing the data using  ...

  9. Vue报错之" [Vue warn]: Unknown custom element: <wzwzihello> - did you register the component correctly? For recursive components, make sure to provide the "name" option."

    一.报错截图 [Vue warn]: Unknown custom element: <wzwzihello> - did you register the component corre ...

随机推荐

  1. js操作Attribute,控件的各种属性.....maxlength,style...

    Attribute是属性的意思,文章仅对部分兼容IE和FF的Attribute相关的介绍. attributes:获取一个属性作为对象 getAttribute:获取某一个属性的值setAttribu ...

  2. sql 所有数据表中 插入字段

    declare @tablename varchar(200)declare @sql varchar(2000)declare cur_t cursor forselect name from sy ...

  3. XAMPP--Apache服务无法启动问题定位及处理

    一.问题简述: XAMPP 在使用一段时间后,Apache服务无法启动. 二.详细描述: 安装Xampp服务器套件之后,部署使用正常.一段时间未使用,再次打开时,Apache服务无法启动.错误提示如下 ...

  4. DatePickerDialog日期对话框以及回调函数的用法

    DatePickerDialog类的实例化需要用到回调接口,如下定义: android.app.DatePickerDialog.DatePickerDialog(Context context, O ...

  5. PAT 甲级1135. Is It A Red-Black Tree (30)

    链接:1135. Is It A Red-Black Tree (30) 红黑树的性质: (1) Every node is either red or black. (2) The root is ...

  6. 329.-io流(字符-练习-复制文本文件二)

    //每次读取的字节长度,一般都是1024的倍数 private static final int BUF_SIZE = 1024; public static void main(String[] a ...

  7. C++ 程序的编译

    一.编译器都具备集成开发环境(Integrated Developed Environment,IDE) 二.程序源文件命名约定: C++ 的后缀一般是 .cpp .cc .C .cpp .cxx 三 ...

  8. C++调用Com

    需求:1.创建myCom.dll,该COM只有一个组件,两个接口:   IGetRes--方法Hello(),   IGetResEx--方法HelloEx() 2.在工程中导入组件或类型库  #im ...

  9. 写给新手的十一条 Docker 守则

    很多人最终还是决定使用 Docker 解决问题. Docker 的优点很多,比如: 一体化——将操作系统.库版本.配置文件.应用程序等全部打包装在容器里.从而保证 QA 所测试的镜像 (image) ...

  10. Python【每日一问】34

    问: 基础题: 定义函数实现以下功能:求出 0-n 所能组成的奇数个数,位数最多 n+1 (0<n<10),比如键盘输入n=7,求出0-7所能组成的奇数个数 提高题: 有如下分数序列: 2 ...