简述vue props和非props的2个特性
props的2个特性
①:父组件通过属性的方式传值(比如下面截图中的content)给子组件,content不会显示在DOM节点中


②:父组件向子组件传递值(content),子组件通过props接收后,可在子组件中直接通过{{}}(插值表达式)或this.content获得content中的内容
Demo
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="root">
<child content="hello world"></child>
</div> <script>
Vue.component('child', {
props: ['content'],
template: '<div>{{content}}</div>'
}) var vm = new Vue({
el: '#root'
})
</script>
</body> </html>
非props的2个特性
①:父组件向子组件传递值(content),子组件没有用props接收,content会显示在DOM节点中


②:父组件通过属性传递值(content),子组件没有通过props接收,此时会报错,提示content没有定义无法使用

Demo
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="root">
<child content="hello world"></child>
</div> <script type="text/javascript">
Vue.component('child', {
// props: ['content'],
template: '<div>{{content}}</div>'
}) var vm = new Vue({
el: '#root'
})
</script>
</body> </html>
简述vue props和非props的2个特性的更多相关文章
- vue组件参数校验与非props特性
组件参数校验 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...
- 4-3 组件参数校验与非props特性
本文参考脚本之家,https://www.jb51.net/article/143466.htm 通过属性的形式,父组件对子组件进行参数的传递 //如下图: //父组件设置content属性,向属性中 ...
- 【js】 vue 2.5.1 源码学习(五) props directives规范化 props 合并策略
大体思路 (四) 上节回顾: A: 对于生命周期函数将父子组件的函数放到一个数组里面,特定时间点调用,保证父子组件函数都调用到. B: 对于directive,filters,components 等 ...
- 从vue源码看props
前言 平时写vue的时候知道props有很多种用法,今天我们来看看vue内部是怎么处理props中那么多的用法的. vue提供的props的用法 1. 数组形式 props: ['name', 'va ...
- vue中直接修改props中的值并未给出警告,为啥?
问:vue中直接修改props中的值并未给出警告,为啥? 答:如果props传入的值是引用类型,在子组件中改变其元素,不改变引用,那么不报错: 如果是基本类型,那么在修改时浏览器控制台会有报错信息. ...
- [Vue @Component] Pass Vue Render Functions as Props for Powerful Patterns
Render functions open up a world of customization and control by using pure JavaScript rather than V ...
- vue中响应式props办法
title: vue中响应式props办法 toc: false date: 2018-12-25 21:22:49 categories: Web tags: Vue 更新props数据时,使用th ...
- js 实现vue—引入子组件props传参
参考:https://www.cnblogs.com/xiaohuochai/p/7388866.html 效果 html <!DOCTYPE html> <html> < ...
- [Recompose] Refactor React Render Props to Streaming Props with RxJS and Recompose
This lesson takes the concept of render props and migrates it over to streaming props by keeping the ...
随机推荐
- poj-3682 King Arthur's Birthday Celebration
C - King Arthur's Birthday Celebration POJ - 3682 King Arthur is an narcissist who intends to spare ...
- 编译安装最新版nettle和gnutls
编译安装最新版gnutls的时候,总是会出libnettle 3.4.1 was not found的报错信息. 即使编译安装了nettle的最新版3.5之后,依然会报该错. 原因是gnutls编译的 ...
- java web工程的配置文件
java web工程的配置文件 1.工程(源码依赖管理) 2.代码生成管理: 3.会话管理:servlet: 4.应用管理: 5.(分布式)资源管理:数据.数据库连接等. pom:源码管理工具 位置: ...
- hook declined to update refs/heads/dev
提交一个项目,push的时候,报错: warning: Large files detected. remote: error: File TaodangpuAuction/TaodangpuAuct ...
- Gradle Wrapper简述
个人博客:http://www.enjoytoday.cn Gradle更多介绍参考:http://www.enjoytoday.cn/categorys/Gradle 案例源码:GitHub gra ...
- hadoop mapreduce求解有序TopN
利用hadoop的map和reduce排序特性实现对数据排序取TopN条数据. 代码参考:https://github.com/asker124143222/wordcount 1.样本数据,假设是订 ...
- [20191012]组成rowid.txt
[20191012]组成rowid.txt --//昨天做了拆分rowid的测试,链接http://blog.itpub.net/267265/viewspace-2659613/=>[2019 ...
- css为图片添加一层蒙版并在上层显示文字等
效果图: 代码如下: <div class="row" style="width:100%; position:relative;z-index:1;margin: ...
- 3.Python网络编程_多任务问题抛出
#单线程程序 import time def sing(): """唱歌5秒钟""" for i in range(5): print(&q ...
- Html学习之五(嵌套之简单购物界面设计)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...