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. Java对象简单实用(计算器案例)

    对 Java中的对象与属性,方法的使用,简单写了个案例 import java.util.Scanner; class Calculste { int a; //定义两个整数 int b; Strin ...

  2. arp学习笔记(linux高性能服务编程)

    先看看arp的定义吧 现在linux运行这条命令 tcpdump -i eth0:1 -ent '(dst 192.168.5.190 and src 192.168.5.109)or( dst 19 ...

  3. cookie、json详解

    什么是cookie 1.cookie是存储于访问者计算机中的变量2.cookie是浏览器提供的一种机制3.可以由js控制(设置.读取.删除)4.cookie可以实现跨页面全局变量可以跨越同域名下多个网 ...

  4. R语言学习 - 箱线图(小提琴图、抖动图、区域散点图)

    箱线图 箱线图是能同时反映数据统计量和整体分布,又很漂亮的展示图.在2014年的Nature Method上有2篇Correspondence论述了使用箱线图的好处和一个在线绘制箱线图的工具.就这样都 ...

  5. js读写txt文件

    view plain<script language="javascript" type="text/javascript"> //读文件funct ...

  6. Apache 和 Nginx 下的 URL 重写

    URL 重写和重定向 URL 重写是将页面映射到本站另一页面, 而重定向则是将页面映射到另一主机(域名). 其中临时重定向(R=302)和永久重定向(R=301)都是亲搜索引擎的, 是 SEO 的重要 ...

  7. Linux(Centos7)下搭建SVN服务器(新手上路)

    以前都是别人直接给地址在svn上,下载或者上传东西,如今要自己建一个版本库用来存放东西.1.安装svnyum install -y subversion 2.查看svn安装位置还有哪些文件rpm -q ...

  8. 洛谷——P1775 古代人的难题_NOI导刊2010提高(02)&& P1936 水晶灯火灵(斐波那契数列)

    P1775 古代人的难题_NOI导刊2010提高(02) P1936 水晶灯火灵 斐波那契数列 1.x,y∈[1…k],且x,y,k∈Z 2.(x^2-xy-y^2)^2=1 给你一个整数k,求一组满 ...

  9. UVA - 10723 Cyborg Genes (LCS)

    题目: 思路: 求两个串的最长公共子序列,则这个最短的串就是给出的两个串的长度和减去最长公共子序列的长度. 状态转移方程: 如果s[i-1]==t[j-1]就有dp[i][j] = dp[i-1][j ...

  10. Jqueryd的一些 总结

    JSP层 /*发送data 主要有三种方式:1.json 数组(推荐1)2.url拼接3.表单的序列化 serialize*/ <script type="text/javascrip ...