vue-(子传父)

子组件:

<template>
  <div>我是左侧内容<button @click="handleClick">向父组件派送数据</button></div>
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue';

let list = reactive<number[]>([4, 5, 6]);

const emit = defineEmits(['HandClick']);

const handleClick = () => {
  emit('HandClick', list);
};
</script>
<style scoped>
div {
  width: 200px;
  height: 100%;
  background: aquamarine;
  text-align: center;
  font-size: 20px;
}
</style>

父组件:

<template>
  <Headler></Headler>
  <div class="content">
    <Menu @HandClick="handleClick"></Menu>
    <Content></Content>
    <button></button>
  </div>
</template>

<script setup lang="ts">
import Headler from './components/Headler.vue';
import Content from './components/Content.vue';
import Menu from './components/Menu.vue';
import { ref, reactive } from 'vue';

const handleClick = (data) => {
  console.log(data, 'data');
};
</script>
<style>
.content {
  display: flex;
  position: absolute;
  top: 80px;
  bottom: 0;
  left: 0;
  right: 0;
}
</style>

 

posted @ 2022-07-21 14:50  银河游鱼  阅读(41)  评论(0编辑  收藏  举报