其他分享
首页 > 其他分享> > vue-(子传父)

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>

 

标签:vue,const,子传父,reactive,components,import,data
来源: https://www.cnblogs.com/bzqs/p/16501907.html