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. 命名秘籍周获近五千星——GitHub 热点速览 v.21.04

    作者:HelloGitHub-小鱼干 命名一直是编程界的难点,这次 naming-cheatsheet 就能帮上你的忙.按照它的 SID(Short..Intuitive.Descriptive)原则 ...

  2. navicat premium 11.0.17 破解版

    下载地址: 链接:https://pan.baidu.com/s/1zBoKRAaQZb2p2weelJpKMQ       提取码:b8dd 一款功能强大的数据库管理工具Navicat Premiu ...

  3. LR_添加系统资源监控失败

    1.服务开启情况:RPC.Rmote Resgistry.Network DDE.Server.Workstation.Network connection以上服务是否已开启 2.是否开了防火墙,如有 ...

  4. Most basic operations in Go are not synchronized. In other words, they are not concurrency-safe.

    Most basic operations in Go are not synchronized. In other words, they are not concurrency-safe. htt ...

  5. JS 实现一个实时动态校验,将输入格式错误的显示为红色背景

    功能描述: 源码: 功能描述: 实时动态校验,如果输入的格式错误,将弹窗提示输入格式错误并将背景展示为红色. 源码: 前台: <hy:formfield name="cxfdl&quo ...

  6. Centos7 yum 安装 oracle-rdbms-server-11gR2-pre

    Oracleyum官方网站 http://yum.oracle.com/ 一.下载yum源 根据自己需求下载相应的yum源 http://yum.oracle.com/getting-started. ...

  7. FortiGate防火墙办公网常用配置

    1.建立主备机 2.配置端口 3.配置SD-WAN 4.新建上网路由 5.新建上网策略 6.建立与其他点的IPSec VPN或点对点专线

  8. idea中将普通工程设置为maven项目

    只需要在工程上右键,"Add Frameworks support...",然后选择Maven即可

  9. 20.LVM

    1.在硬盘分好区或者部署为RAID 磁盘阵列之后,再想修改硬盘分区大小就不容易了.换句话说,当用户想要随着实际需求的变化调整硬盘分区的大小时,会受到硬盘"灵活性"的限制. 这时就需 ...

  10. (23)gzip命令:压缩文件或目录&&gunzip命令:解压缩文件或目录

    1.gzip 是 Linux 系统中经常用来对文件进行压缩和解压缩的命令,通过此命令压缩得到的新文件,其扩展名通常标记为".gz". 再强调一下,gzip 命令只能用来压缩文件,不 ...