[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 合并压缩 参考司徒正美 ...
随机推荐
- 囧 appspot.com/
囧 appspot.com/ 我负责公司人事,最近车间招了一批外来打工妹,让她们填写个人资料表格,早上在看表格登记,发现其中一张政治面貌一栏赫然写着"瓜子脸",当时笑得眼泪直流,没 ...
- 解决浏览器不兼容websocket
本例使用tomcat 7.0的websocket做为例子. 1.新建web project.2.找到tomcat 7.0 lib 下的 catalina.jar,tomcat-coyote.jar添加 ...
- 自定义HTML标签属性
为HTML元素添加一自定义的属性非常方便,只须将其加到尖括号中即可,与内置属性地位相等. 如我们要为TextBox元素添加属性idvalue: <input type="text&qu ...
- AAC编解码
AAC编码可以使用faac /** 初始化 @param sampleRate 音频采样率 @param channels 通道数 @param bitSize 音频采样精度 16 */ - (voi ...
- 笔记二:JS的输出、语法、语句、字符串、条件语句、switch语句、for循环、while循环
1.JS的输出: 注意:JS没有任何打印或者输出的函数 JS输出数据的集中方法: 1.使用window.alert()弹出警告框: 2.使用document.write()方法将内容写到HTML文档 ...
- dbms_stats
dbms_stats全部的功能包例如以下: GATHER_INDEX_STATS:分析索引信息 GATHER_TABLE_STATS:分析表信息,当cascade为true时,分析表.列(索引)信息 ...
- Swift iOS tableView static cell动态计算高度
TableView是iOS开发中经常使用的组件.有些表格由于UILabel包括的文本字数不一样,须要显示的高度也会不同,因此须要动态计算static cell的高度.我用的是static cell,注 ...
- 启动Tomcat,startup.bat一闪而过的解决办法
1.打开命令行:win+R --> cmd2.将解压后的tomcat\bin\startup.bat文件拖到控制台窗口中,回车. 这样就可以看到错误信息的提示,根据提示修改即可.
- [D3] Modify DOM Elements with D3 v4
Once you can get hold of DOM elements you’re ready to start changing them. Whether it’s changing col ...
- 如何在Win8/Win10上开启 dotNetFramework 2.0/3.5 功能
问题: 在Windows 8.Windows 10上安装一些软件时,系统可能会报出如下错误:你的电脑上的应用需要使用以下Windows功能: 解决方式: 首先呢,你需要准备好一个Win8/ ...