子组件给父组件的值传递
传递数据方法:
- 在子组件中的调用方法里,也就是this.$emit(“自定义名”, “参数”),写进需要传递的数据。
- 然后再父组件中的方法中添加参数,fn(参数){}
首先你就得认识父组件如何传递方法给子组件。因为这就是在这基础上添加emit的使用。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../SASS/tailwind.css">
</head>
<body>
<div id="app">
<!--在父组件中使用v-on/@自定义名="要传递的方法"-->
<component1 @parent-show="fatherClick">