Vue你不知到的$this.emit()的用法
需求


需求:除了拿到false,还要拿到v-for中的index
如何解决:再使用一次父传子,:a="index" 将下标值传递给子组件 注意要加引号
子组件
<template>
<!-- 子组件 -->
<div>
<h2 @click="getcon">123--{{a}}</h2>
</div>
</template>
<script>
export default {
props: ["a"],
methods: {
getcon() {
this.$emit("handlerchange", [this.a, false]);
}
}
};
</script>
父组件
<template>
<div>
<div v-for="(item,index) in arr" :key="index" class="box">
<h2>标题</h2>
<p>{{item.name}}</p>
<experts @handlerchange="ChangeV" :a="index"></experts>
</div>
</div>
</template> <script>
import experts from "../../../components/myExperts";
export default {
data() {
return {
arr: [
{ name: "张三", id: "1" },
{ name: "张四", id: "2" },
{ name: "王五", id: "3" }
]
};
},
components: {
experts
},
methods: {
ChangeV(meass) {
console.log(meass);
}
}
};
</script>
<style scoped>
.box {
margin-top: 20px;
}
</style>

Vue你不知到的$this.emit()的用法的更多相关文章
- Vue 子组件调用父组件 $emit
<!DOCTYPE html><html> <head> <meta charset="utf-8"> ...
- 第四节:Vue表单标签和组件的基本用法,父子组件间的通信
vue表单标签和组件的基本用法,父子组件间的通信,直接看例子吧. <!DOCTYPE html> <html> <head> <meta charset=&q ...
- vue条件语句v-if、v-else、v-else-if用法
vue条件语句v-if.v-else.v-else-if用法 v-if 是“真正”的条件渲染,因为它会确保在切换过程中条件块内的事件监听器和子组件适当地被销毁和重建.v-if 也是惰性的:如果在初始渲 ...
- vue的通讯与传递props emit (简单的弹框组件)
props父把信息传递给子组件 1父组件 <template> <div class="hello"> <div id="app-3&quo ...
- 【Vue】---- 手动封装on,emit,off
一.概念 1. $on("事件名称",回调函数) 事件绑定,一个事件名称上面可能绑定多个函数 2. $emit("事件名称",需要传递的值) 事件触发时,会触发 ...
- vue基础----组件通信(props,$emit,$attrs,$listeners)
一.父传子,子传孙 1. props 1>在父组件中通过子组件自定义的标签属性来传递数据. 2>在子组件中通过props声明希望用到的数据 <body> <div id= ...
- vue中 关于$emit的用法
1.父组件可以使用 props 把数据传给子组件.2.子组件可以使用 $emit 触发父组件的自定义事件. vm.$emit( event, arg ) //触发当前实例上的事件 vm.$on( ev ...
- vue传值 ---- >> 子传父,$emit()
划重点: $emit 绑定一个自定义事件event,当这个这个语句被执行到的时候,就会将参数arg传递给父组件,父组件通过@event监听并接收参数. 子组件: 1 <template& ...
- vue中$attrs和$listeners以及inheritAttrs的用法
官方文档说明: 一.解释:包含了父作用域中不作为 prop 被识别 (且获取) 的特性绑定 (class 和 style 除外). 意思就是父组件往子组件传没有在props里声明过的值时,子组件可以通 ...
随机推荐
- Redis入门(四)-Java操作Redis
<Redis入门>系列文章的第四篇,这一节看一下如何用Java版本的redis客户端工具--Jedis来操作redis. Jedis封装了丰富的api来对redis的五种数据类型 stri ...
- Spring Boot 为什么这么火?
没错 Spring Boot 越来越火了,而且火的超过了我的预期,作为一名行走一线的 Java 程序员,你可能在各个方面感受到了 Spring Boot 的火. Spring Boot 的火 技术社区 ...
- `http-equiv` meta 标签
来看以下有趣的代码, <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv=& ...
- 在IIS上部署 .Net Core 3.0 项目踩坑实录
在IIS上部署 .Net Core 3.0 项目的主要流程有: 安装并启用IIS 安装AspNetCoreModuleV2 添加.配置网站 设置应用程序池 通过VS发布 一.安装并启用IIS: 安装了 ...
- C# 委托汇总
委托汇总以及遗留问题: using System; using System.Collections.Generic; using System.Linq; using System.Text; us ...
- Filter Lookup Editor Data Source 筛选器查找编辑器数据源
In this lesson, you will learn how to filter the data displayed by a lookup editor. This editor is s ...
- Git实战指南----跟着haibiscuit学Git(第七篇)
笔名: haibiscuit 博客园: https://www.cnblogs.com/haibiscuit/ Git地址: https://github.com/haibiscuit?tab=re ...
- MySQL8.0+常用命令
开启远程访问 通过以下命令开启root用户远程访问权限: CREATE USER 'root'@'%' IDENTIFIED BY 'password'; GRANT ALL ON *.* TO 'r ...
- 文本切换器(TextSwitcher)的功能与用法
TextSwitcher继承了ViewSwitcher,因此它具有与ViewSwitcher相同的特征:可以在切换View组件时使用动画效果.与ImageSwitcher相似的是,使用TextSwit ...
- linux下通过命令连接wifi
故事背景:我司是做新零售的,机器支持4G.wifi.网线,可能会涉及到网络的切换和连接 项目需求:用户在web端输入wifi名称和密码,客户端可以通过服务端下发的信息进行连接 技术调研:之前提到过nm ...