【Vue】中 $attrs 中的使用方法
vue官网是这样介绍的:
包含了父作用域中不作为 prop 被识别 (且获取) 的特性绑定 (class 和 style 除外)。当一个组件没有声明任何 prop 时,这里会包含所有父作用域的绑定 (class和 style 除外),并且可以通过 v-bind="$attrs" 传入内部组件——在创建高级别的组件时非常有用。
<div id="app">
A{{msg}}
<my-button :msg="msg"></my-button>
</div>
<script>
let vm = new Vue({
el: '#app',
data: {
msg: ''
},
components: {
'MyButton': {
props: ['msg'],
template: `<div>B<my-input :msg="msg"></my-input></div>`,
components: {
'MyInput': {
props: ['msg'],
template: '<div>C{{msg}}</div>'
}
}
}, }
})
</script>
<script>
let vm = new Vue({
el: '#app',
data: {
msg: ''
},
components: {
'MyButton': {
// props: ['msg'],
template: `<div>B<my-input v-bind="$attrs"></my-input></div>`,
components: {
'MyInput': {
props: ['msg'],
template: '<div>C{{msg}}</div>'
}
}
}, }
})
</script>
注意组件别写错了,组件是在父级模板中使用的,最外层的也是模板,el表示模板挂载在哪个元素的位置
【Vue】中 $attrs 中的使用方法的更多相关文章
- vue中methods一个方法调用另外一个方法
转自http://blog.csdn.net/zhangjing1019/article/details/77942923 vue在同一个组件内: methods中的一个方法调用methods中的另外 ...
- vue不通过路由直接获取url中参数的方法示例
vue不通过路由直接获取url中参数的方法示例 vuejs取得URL中参数的值地址:http://localhost:3333/#/index?id=128console.log(this.$rout ...
- 060——VUE中vue-router之路由嵌套在文章系统中的使用方法:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 059——VUE中vue-router之路由嵌套在文章系统中的使用方法:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue中代理实现方法
vue中代理实现方法如下: const path = require('path'); function resolve(dir) { return path.join(__dirname, dir) ...
- vue项目开发中遇到的几个问题
1.使用elment或者mintUI库时,需要全局引入ui库的css文件:然后在修改自己样式时,需要将自己的css文件引入到main.js中才会生效,全局引用2.使用v-html展示dom字符串时,相 ...
- vue-learning:41 - Vuex - 第二篇:const store = new Vue.Store(option)中option选项、store实例对象的属性和方法
vuex 第二篇:const store = new Vue.Store(option)中option选项.store实例对象的属性和方法 import Vuex from 'vuex' const ...
- Vue 2.6 中部分引入 TypeScript 的方法
在 Vue 与 Cesium 联合开发的过程中,我发现很多 Cesium 代码不宜直接写在 .vue 文件中.同时由于 Cesium 库较为复杂,不借助 TypeScript 的静态类型会导致代码难维 ...
- 【转载】 C#中使用CopyTo方法将List集合元素拷贝到数组Array中
在C#的List集合操作中,有时候需要将List元素对象拷贝存放到对应的数组Array中,此时就可以使用到List集合的CopyTo方法来实现,CopyTo方法是List集合的扩展方法,共有3个重载方 ...
随机推荐
- A1134. Vertex Cover
A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...
- A1034. Head of a Gang
One way that the police finds the head of a gang is to check people's phone calls. If there is a pho ...
- C++常见函数使用
备注:总结C++中一些常见函数的使用,提高工作效率 数组的拼接: //报文头的前6B固定 DRV_UCHAR pkt_info_head[PALIVE_TO_NP_LEN] = {0x70, 0xff ...
- 第四篇 - 爬取前程无忧python相关工作
环境:python3 pycharm 模块:requests,xlwt,urllib.request,re 正常三步走: 1.获取源代码 2.匹配源代码,获得目标数据 3.存储到文件中 直接上代 ...
- FluentScheduler定时器计划任务
http://www.cnblogs.com/lgxlsm/p/6734011.html 用了FluentScheduler后,再也比想用timer计时器了. FluentScheduler 是 .N ...
- c/c++ 大于等于 大于 时间效率比较
变成汇编,都是: 大于等于和大于都是电路上的处理,时间上应该差不多.
- PMP学习经验总结——ITTO第六版教材
今天小编送的都是干货哦!大家可以收藏一下对学习PMP和项目管理都有很大收获. 4.1 制定项目章程——启动——一次或仅在项目的预定义点开展 概念:编写一份正式批准项目并授权项目经理在项目活动中使用组织 ...
- terminate called without an active exception异常
在gcc4.4下,采用回调机制写了一个类似std::thread的线程类. 但是使用时却发生了核心已转移的错误. main函数调用的代码大致是 int main(int argc, char *arg ...
- 移动端click事件延时
在移动端使用click事件会产生300ms的延迟 问题的产生: 移动端存在双击放大的问题,所以在移动端点击事件发生时,为了判断用户的行为(到底是要双击还是要点击),浏览器通常会等待300ms,如果30 ...
- please select android sdk