[Vue @Component] 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.
In the previous post about dynamic component
<component :is="selectedComp"></component> <script>
import Vue from "vue"
import { Component, Prop } from "vue-property-decorator" 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: { }
})
export default class App extends Vue {
comps = [One, Two, Three]
selectedComp = this.comps[0]
}
</script>
Because inside @Component({components: {}}) haven't register those component 'One, Two, Three', so then using
<component :is="selectedComp"></component>
'selectedComp' has to ben a real functional component.
But If we have registered the components:
@Component({
components: {
One, Two, Three
}
})
The the 'selectedComp' can be just component's name:
selectedComponent = 'One' | 'Two' | 'Three'
<keep-alive> Component:
Components might have some state, you want to keep the state instead of losting it, you can use 'keep-alive' component:
<keep-alive>
<component v-bind:is="currentView" v-bind:initial-quantity="item.quantity" v-bind:name="item.text" v-bind:diet="item.diet"></component>
</keep-alive>
[Vue @Component] Dynamic Vue.js Components with the component element的更多相关文章
- [Vue] Dynamic Vue.js Components with the component element
You can dynamically switch between components in a template by using the reserved <component> ...
- vue报错[Vue warn]: Unknown custom element: <router-Link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
vue浏览器报错,如下 vue.runtime.esm.js?2b0e:619 [Vue warn]: Unknown custom element: <router-Link> - di ...
- 前端框架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 ...
- 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 ...
- [Vue @Component] Extend Vue Components in TypeScript
This lesson shows how you can extend and reuse logic in Vue components using TypeScript inheritance. ...
- [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 ...
- [Vue @Component] Load Vue Async Components
Vue provides a straight-forward syntax for loading components at runtime to help shave off initial b ...
- 使用Vue自定义组件时,报did you register the component correctly? For recursive components, make sure to provide the "name" option.(未注册组件)的原因之一
错误信息: [Vue warn]: Unknown custom element: <list> - did you register the component correctly? F ...
- [Vue warn]: Unknown custom element: <sapn> - did you register the component correctly? For recursive components, make sure to provide the "name" option. found in ---> <Evaluate> at src/views/index/
关于vue报错: [Vue warn]: Unknown custom element: <sapn> - did you register the component correctly ...
随机推荐
- Silverlight环境配置
今天对Silverlight安装环境进行了配置,本系统已经安装VS2010 和 Silverlight 5. 要开发Silverlight必须安装Developer Runtime 和 SDK , 且 ...
- Winform学习知识汇总
引用博客 http://www.cnblogs.com/peterzb/archive/2009/06/14/1502918.html
- [ POI 2012 ] Letters
\(\\\) \(Description\) 给出两个长度为 \(N\) 的字符串\(S_1,S_2\),且保证两个字符串中每一个字符出现次数相同. 现在一次操作可以交换相邻的两个字符,问将 \(S_ ...
- Python之数据聚合与分组运算
Python之数据聚合与分组运算 1. 关系型数据库方便对数据进行连接.过滤.转换和聚合. 2. Hadley Wickham创建了用于表示分组运算术语"split-apply-combin ...
- RabbitMQ 为什么需要信道?为什么不是TCP直接通信?
交换器和队列的关系 1. 交换器是通过路由键和队列绑定在一起的,如果消息拥有的“路由键”跟队列和交换器的“路由键”匹配,那么消息就会被路由到该绑定的队列当中去 2. 也就是说,消息到队列的过程中,消息 ...
- 【转载】 python sort、sorted高级排序技巧
这篇文章主要介绍了python sort.sorted高级排序技巧,本文讲解了基础排序.升序和降序.排序的稳定性和复杂排序.cmp函数排序法等内容,需要的朋友可以参考下 Python list内置so ...
- 7z.exe 命令行压缩文件排除文件(exclude filenames) 手记
命令行使用格式:Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] ...
- day16-常用模块I(time、datetime、random、os、sys、json、pickle)
目录 time模块 datetime模块 random模块 os模块 sys模块 json模块与pickle模块 json pickle time模块 time模块一般用于不同时间格式的转换,在使用前 ...
- 【转载】jxl的使用总结(java操作excel)
jxl.jar是通过java操作excel表格的工具类库: 链接:https://pan.baidu.com/s/1AAT_eA_Q47zFeQohap6eQg 提取码:777b 1:通过模拟实现创建 ...
- Android 按钮常用点击事件大总结
很多学习Android程序设计的人都会发现每个人对代码的写法都有不同的偏好,比较明显的就是对控件响应事件的写法的不同.因此本文就把这些写法总结一下,比较下各种写法的优劣,希望对大家灵活地选择编码方式可 ...