props与data中的key不能一样
//子组件
<template>
<div>
<div>{{ name.age }}</div>
<button @click="changename">改变内容</button>
</div>
</template>
<script>
export default {
name: "",
props: {
name: Object,
},
data() {
return {
names: {
sex: "dr3",
age: "3455",
class: "de",
},
};
},
model: {
prop: "name",
event: "input",
},
methods: {
changename() {
this.$emit("input", this.names);
},
},
components: {},
};
</script>
<style></style>
//父组件
<template>
<div>
<Mine v-model="name" />
</div>
</template>
<script>
import Mine from "./components/Mine.vue";
export default {
name: "App",
data() {
return {
name: {
sex: "dr",
age: "34",
class: "de",
},
};
},
components: {
Mine,
},
};
</script>
<style></style>