【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个重载方 ...
随机推荐
- A1146. Topological Order
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- ES6---扩展运算符和rest‘...’(三点运算符),在数组、函数、set/map等中的应用
ES6新增的三点运算符,是由三个点表示,在数组中扮演着重要的角色,可以对数组进行合并与分解.可以对set等数据结构进行转换.可以对函数参数进行简化表示,接下来,我们一起揭开其神秘面纱… ●三点—res ...
- ASCLL、Unicode和UTF-8编码的理解
我们已经讲过了,字符串也是一种数据类型,但是,字符串比较特殊的是还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit) ...
- HTML学习笔记Day5
一.CSS属性 1.文本溢出是否“...”显示属性:text-overflow:clip(不显示省略标记)/ellipsis(文本溢出时“...”显示) 定义此属性有四个必要条件:1)须有容器宽度:w ...
- (二叉树 BFS) leetcode103. Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- String类中"=="、equals和普通类中"=="、equals的比较
package cn.method.demo; public class StringDemo2 { public static void main(String[] args) { String s ...
- bzoj3237 cdq分治+可撤销并查集
https://www.lydsy.com/JudgeOnline/problem.php?id=3237 年轻的花花一直觉得cdq分治只能用来降维,不料竟然可以用来分治询问 N<=100000 ...
- 在linux下面解压用的zxpf是什么意思,它跟zxvf有啥区别
在linux下面解压用的zxpf是什么意思,它跟zxvf有啥区别 linux 命令中tar后跟的zxvf是什么意思:.tar.gz是一个压缩包 .tar只是打包而没有压缩 z:表示 tar 包是被 ...
- Try It Once Again
愿你就是自己最暖的太阳.无需凭借谁的光~~~~~~~~~~~~ ============================== ============================== ====== ...
- tomcat插件使用
1.pom.xml添加插件 <build> <plugins> <!-- tomcat7插件 --> <!-- 注意:目前来说,maven中央仓库还没有tom ...