非props特性
2019-11-28 本文已影响0人
未来在奋斗
<!--
非 props 特性:
调用组件时传递给组件的参数,如果在这个组件内部没有通过 props 选项去定义的话,那么这个 prop 就叫做 非props
非 props 特性的一些规则
1. 会自动添加到组件的根元素上 (继承)
2. 普通的非props特性都是替补,但 class 与 style 是拼接
3. 禁用继承 inheritAttrs class 与 style 是禁用不了的
4. 可以在组件内通过 this.$attrs 获取到非props 特性, class 与style 不在此列
-->
<div id="app">
<cpn class="box2" style="font-size:20px" name="张三" age="18" sex="男"> </cpn>
</div>
</body>
<script src="vue.js"></script>
<script>
// inheritAttrs: false, // 这样会禁止替换
Vue.component('cpn',{
props:['name'],
template:`
<div class="box1" style="color:red" age = "20">
<h1>hello</h1>
<p>{{$attrs}}</p>
</div>
`
})
let vm = new Vue({
el: '#app'
})