vue component :is

Vue <component> element

https://vuejs.org/v2/guide/components.html#Dynamic-Components


https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-dynamic-components-with-binding?file=/index.html

https://codesandbox.io/s/github/vuejs/vuejs.org/tree/master/src/v2/examples/vue-20-dynamic-components

https://codesandbox.io/s/interesting-saha-o7g5q

:is

https://vuejs.org/v2/api/#v-bind

https://stackoverflow.com/questions/6003819/what-is-the-difference-between-properties-and-attributes-in-html#answer-6004028

keep-alive

wrap dynamic component with a <keep-alive> element

https://vuejs.org/v2/guide/components-dynamic-async.html


<!-- Inactive components will be cached! -->
<keep-alive>
<component v-bind:is="currentTabComponent"></component>
</keep-alive>

demo


<div id="app">
<h1>vue & directives</h1>
<!-- v-model -->
<input v-model="content.message">
<!-- 自定义组件 -->
<component
:is="someComponent"
:datas="content"
:update-data="content">
<h1>1. vue component component</h1>
</component>
<!-- v-bind: -->
<something
:datas="content"
:update-data="content">
<h1>2. something component</h1>
</something>
<p>
<span v-if="obj.id === `007`">{{obj.id}}</span>
<span v-else>unknown id</span>
</p>
<p>
<span>{{rawHTML}}</span>
</p>
<p>
<span v-html="rawHTML"></span>
</p>
</div>

// 自定义组件 component
const something = {
template: `
<div>
<slot></slot>
<pre>{{ updateData }}</pre>
</div>
`,
props: {
updateData: Object,
datas: {
type: Object,
required: true,
},
},
watch: {
updateData: {
handler (val) {
// console.log('watch', val.message);
},
deep: true,
},
datas: {
handler (obj) {
console.log('obj =', obj.message);
},
deep: true,
},
},
}; // 实例化
const vm = new Vue({
el: '#app',
data () {
return {
content: {
message: `hello world!`,
},
obj: {
id: `007`,
name: `UFO`,
},
rawHTML: `<span style="color: red">This should be red.</span>`,
// rename
someComponent: something,
};
},
components: {
something,
},
});

refs

https://codepen.io/xgqfrms/pen/dypYXme?editors=1111



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


vue component :is的更多相关文章

  1. Vue.component注意事项

    Vue.component前不要加 new,否则报错: Uncaught TypeError: Cannot read property '_base' of undefined

  2. Vue.extend和Vue.component的联系与差异

    extend 是构造一个组件的语法器. 你给它参数 他给你一个组件 然后这个组件 你可以作用到Vue.component 这个全局注册方法里, 也可以在任意vue模板里使用apple组件 var ap ...

  3. Vue中使用Vue.component定义两个全局组件,用单标签应用组件时,只显示一个组件的问题和 $emit的使用。

    解决方法: 定义了两个 Vue.component 在 el 中使用的时候要用 双标签, 用单表标签的时候,只会显示第个 组件间 这样写只显示 welcome-button 组件 <welcom ...

  4. vue-property-decorator 提供 OO 的风格 Vue Component 方便类型声明

    @Prop  父子组件之间传值 Install: npm install --save vue-property-decorator Child: <template> <div&g ...

  5. Vue vue.extend 和vue.component 两则之间的区别

    Vue.extend 返回的是一个 扩展实例构造器, 也就是一个预设了部分选项的Vue实例构造器 Var myExtend = Vue.extend({ //预设选项 })//返回一个 扩展实例构造器 ...

  6. 使用 Vue.component

    引入 vue.js. HTML <div id="app"></div> CSS .greeting { padding: 3rem 1.5rem; bac ...

  7. vue.extend与vue.component的区别和联系

    一味的闷头开发,却对基础概念缺乏理解,是个大坑... 查阅官网后现对自己的理解记录一下,用于日后复习巩固 Vue.extend({}) 简述:使用vue.extend返回一个子类构造函数,也就是预设部 ...

  8. element-ui + el-dialog + Vue.component 注册的富文本控件 第二次及以后打开dialog出现问题解决方法

    自定控件 添加属性  v-if="dialogVisible" <el-dialog title="" :visible.sync="dialo ...

  9. [Vue @Component] Extend Vue Components in TypeScript

    This lesson shows how you can extend and reuse logic in Vue components using TypeScript inheritance. ...

  10. Vue.mixin Vue.extend(Vue.component)的原理与区别

    1.本文将讲述 方法 Vue.extend Vue.mixin 与 new Vue({mixins:[], extend:{}})的区别与原理 先回顾一下 Vue.mixin 官网如下描述: Vue. ...

随机推荐

  1. Go 语言编译过程

    走进Golang之编译器原理_大愚Talk-CSDN博客 https://blog.csdn.net/hel12he/article/details/103061921 go编译器 - 知乎 http ...

  2. 我们都可以把它放 Sidecar 容器中,这样微服务具备了 Super power,一种超能力

    云原生时代,微服务如何演进? 原创 李响 阿里技术 2020-08-28   https://mp.weixin.qq.com/s/KQG2U8_aotDL4YFB8ee6Zw 一  微服务架构与云原 ...

  3. Why failover-based implementations are not enough Redis分布式锁实现 SET resource_name my_random_value NX PX 30000

    核心 SET resource_name my_random_value NX PX 30000 Distributed locks with Redis – Redis https://redis. ...

  4. Salt (cryptography)

    Salt (cryptography) Here is an incomplete example of a salt value for storing passwords. This first ...

  5. # Set the asyncio reactor's event loop as global # TODO: Should we instead pass the global one into the reactor?

    daphne/server.py at master · django/daphne https://github.com/django/daphne/blob/master/daphne/serve ...

  6. 【PostgreSQL】PostgreSQL数据库浅析

    前言 工作中数据库用的不多,大部分都是简单查询一下了事,某项目中突然要求后端进行比较全面的数据库操作,现对自己学到的东西做一下总结. 简介 废话不多说,上官网地址: PostgreSQL 9.4.4 ...

  7. how2j 仿天猫j2EE零散笔记

    1. 在servlet中拼接  :"http://localhost:8080/tmall/admin_property_list?cid=83"  这句话中的cid=83时, c ...

  8. Prometheus监控Kafka

    Prometheus监控Kafka 1.Prometheus监控Kafka,Docker方式 Kafka监控优秀博文: 简书:whaike:[监控]Kafka - 详细指标 CSDN:GeekXuSh ...

  9. java架构《并发编程框架篇 __Disruptor》

    Disruptor入门   获得Disruptor 可以通过Maven或者下载jar来安装Disruptor.只要把对应的jar放在Java classpath就可以了. 基本的事件生产和消费 我们从 ...

  10. IP路由__静态路由

    1.静态路由的优缺点: 优点:对于路由器的CPU没有管理性开销,它意味着如果你不使用动态路由选择的话,你可能应该购买更为便宜的路由器.在路由器之间没有带宽占用,它意味着在WAN链接中你可以节省更多的钱 ...