子组件通过事件的方式,利用 $emit 给父组件传值。
<template>
<div class="child">
<button @click="toFa"></button>
</div>
</template>
<script>
export default {
data() {
return {
imgFile:[]
};
},
methods: {
toFa() {
this.$emit("data", this.imgFile);
}
}
};
</script>
<template>
<div class="parent">
<child @data="getData"></child>
</div>
</template>
<script>
import { child } from "./child";
export default {
components: { child },
data() {
return {
imgFiles:[]
};
},
methods: {
getData(value) {
// value 就是子组件传递过来的数据
this.imgFiles=value;
}
}
};
</script>