[Vue] Dynamic Vue.js Components with the component element
You can dynamically switch between components in a template by using the reserved <component> element and dynamically bind to its is attribute. By using <keep-alive> you can tell Vue to keep the component in memory.
Two children components:
<!-- show.vue --> <template>
<div>
Show Component: <span>{{name}}</span>
</div>
</template>
<script>
export default{
name: 'show-component',
props: ['name']
}
</script>
<!-- edit-->
<template>
<div>
Edit component: <input type="text" v-model="editValue"/>
</div>
</template>
<script>
export default{
name: 'edit-component',
data(){
return{
editValue: this.name
}
},
props: ['name']
}
</script>
Parent:
<template>
<section class="container">
<section>
<h3>Dynamic component</h3>
<a @click="toggle">{{toggleButton}}</a>
<keep-alive>
<component
v-bind:is="currentView"
v-bind:name="message"
>
</component>
</keep-alive>
</section>
</section>
</template>
<style scoped>
.title
{
margin: 50px 0;
}
</style>
<script>
import ShowComponent from '../components/show';
import EditComponent from '../components/edit';
export default {
data() {
return {
message: 'this is my vue!',
currentView: "ShowComponent"
}
},
computed: {
toggleButton: function() {
return this.currentView === "ShowComponent" ?
'show': 'Edit';
}
},
components: {
EditComponent,
ShowComponent
},
methods: {
toggle() {
this.currentView =
this.currentView === "ShowComponent" ?
"EditComponent" : "ShowComponent";
}
}
}
</script>
[Vue] Dynamic Vue.js Components with the component element的更多相关文章
- [Vue @Component] Dynamic Vue.js Components with the component element
You can dynamically switch between components in a template by using the reserved <component> ...
- vue & dynamic components
vue & dynamic components https://vuejs.org/v2/guide/components-dynamic-async.html keep-alive htt ...
- Vue dynamic component All In One
Vue dynamic component All In One Vue 动态组件 vue 2.x https://vuejs.org/v2/guide/components-dynamic-asyn ...
- 前端笔记之Vue(七)Vue-router&axios&Vue插件&Mock.js&cookie|session&加密
一.Vue-router(路由) 1.1路由创建 官网:https://router.vuejs.org/zh/ 用 Vue.js + Vue Router 创建单页应用,是非常简单的.使用 Vue. ...
- Vue.mixin Vue.extend(Vue.component)的原理与区别
1.本文将讲述 方法 Vue.extend Vue.mixin 与 new Vue({mixins:[], extend:{}})的区别与原理 先回顾一下 Vue.mixin 官网如下描述: Vue. ...
- Vue Vue.use() / Vue.component / router-view
Vue.use Vue.use 的作用是安装插件 Vue.use 接收一个参数 如果这个参数是函数的话,Vue.use 直接调用这个函数注册组件 如果这个参数是对象的话,Vue.use 将调用 ins ...
- 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 十五 ║Vue基础:JS面向对象&字面量& this字
缘起 书接上文<从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 十四 ║ VUE 计划书 & 我的前后端开发简史>,昨天咱们说到了以我的经历说明的web开发经历的 ...
- vue中的js引入图片,必须require进来
需求:如何components里面的index.vue怎样能把assets里面的图片拿出来. 1.在img标签里面直接写上路径: <img src="../assets/a1.png& ...
- require.js 加载 vue组件 r.js 合并压缩
https://www.taoquns.com 自己搭的个人博客 require.js 参考阮一峰 Javascript模块化编程(三):require.js的用法 r.js 合并压缩 参考司徒正美 ...
随机推荐
- DG观察日志传输
--primary端查询v$archived_log视图,确认日志是否被应用: set lines 300 pages 300 col name for a20 select name,dest_ ...
- BZOJ2733: [HNOI2012]永无乡(线段树合并)
Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示.某些岛之间由巨大的桥连接,通过桥可以 ...
- 005 python 整数类型/字符串类型/列表类型/可变/不可变
可变/不可变类型 可变类型 ID不变的情况下,值改变,则称之为可变类型,如列表,字典 不可变类型 值改变,ID改变,则称之为不可变类型,如 整数 字符串,元组 整数类型 int 正整数 用途就是记录年 ...
- 03002_MySQL数据库的安装和配置
1.MySQL的安装 (1)下载mysql-5.5.49-win32.msi, 链接:MySQL安装包下载 密码:geqh : (2)打开下载的MySQL安装文件mysql-5.5.27-win32. ...
- 建立一个 Openshift "Do-It-Yourself" 应用
建立一个 Openshift "Do-It-Yourself" 应用 Openshift 的 "Do-It-Yourself" 就是自己可以编译定制 WEB ...
- .net core 时间格式转换
//string time = "2019-01-18 13:50:38"; string time = "2019-01-18 13:50:38 256"; ...
- 11.typeid
#include <iostream> using namespace std; void main() { int a; cout << typeid(a).name() & ...
- RMAN DUPLICATE ADG DEMO
RMAN DUPLICATE ADG DEMO 生产环境谨慎使用,建议生产环境采用RMAN备份恢复的方式. 本演示案例所用环境: primary standby OS Hostname pry s ...
- Eclipse如何从导入SVN上导入项目
1.右键单击,选择 Import,进入导入项目窗口 2.点击选择从SVN检出项目,点击Next下一步 3.选择创建新的资源库位置,点击Next,如果项目之前已经导入过删除掉了,重新导入的时候,只需勾选 ...
- mongodb查询部分满足条件的列
db.tblorders.createIndex( { orderid : -1 },{background:true, name:"index_orderid"} ); db.o ...