[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 合并压缩 参考司徒正美 ...
随机推荐
- CISP/CISA 每日一题 19
CISSP 每日一题(答)What determines how often an audit should be performed? Risk What policy requires u ...
- http的原理
工作原理:客户机与服务器建立连接之后,发送一个请求给服务器,请求格式为统一资源标识符.协议版本号.(请求行.请求头.请求体),服务器接收请求后给予相应,包括相应行,响应头,响应体. ...
- [NPM] Publish npm packages using npm publish
In this lesson we will publish our package. We will first add a prepublish script that runs our buil ...
- 【C语言】编写函数实现库函数atoi,把字符串转换成整形
//编写函数实现库函数atoi.把字符串转换成整形 #include <stdio.h> #include <string.h> int my_atoi(const char ...
- 1.一个WEB应用的开发流程
先说项目开发过程中团队人员的分工协作. 一.人员安排 毕业至今的大部分项目都是独立完成,虽然也有和其他同事协作的时候,但自认为对团队协作的了解和认知都还有所欠缺.很清楚团队协作的重要性,但尚未有很好的 ...
- 10. Spring Boot JDBC 连接数据库
转自:https://blog.csdn.net/catoop/article/details/50507516
- 三星Galaxy Tab S2上市,压制苹果之心凸显
平板市场正在迎来史上最为关键的一次PK,众所周知,平板市场的苹果和三星一直是行业的领头羊,而在激烈的竞争中.三星平板似乎后劲更足.众多性能优异的产品频频推出.平板之王的称谓呼之欲出. 去年三星 ...
- Traveler Nobita (zoj 3456 最小生成树)
Traveler Nobita Time Limit: 2 Seconds Memory Limit: 65536 KB One day, Nobita used a time machin ...
- android图片文件的路径地址与Uri的相互转换
一个android文件的Uri地址一般如下: content://media/external/images/media/62026 这是一张图片的Uri,那么我们如何根据这个Uri获得其在文件系统中 ...
- BUFSIZ
转http://www.judymax.com/archives/262 今天在看示例程序时冒出来一句args = emalloc(BUFSIZ); BUFSIZ是什么意思,查了一下才明白. 这是st ...