props与data中的key不能一样

    1. //子组件
    2. <template>
    3. <div>
    4. <div>{{ name.age }}</div>
    5. <button @click="changename">改变内容</button>
    6. </div>
    7. </template>
    8. <script>
    9. export default {
    10. name: "",
    11. props: {
    12. name: Object,
    13. },
    14. data() {
    15. return {
    16. names: {
    17. sex: "dr3",
    18. age: "3455",
    19. class: "de",
    20. },
    21. };
    22. },
    23. model: {
    24. prop: "name",
    25. event: "input",
    26. },
    27. methods: {
    28. changename() {
    29. this.$emit("input", this.names);
    30. },
    31. },
    32. components: {},
    33. };
    34. </script>
    35. <style></style>
    1. //父组件
    2. <template>
    3. <div>
    4. <Mine v-model="name" />
    5. </div>
    6. </template>
    7. <script>
    8. import Mine from "./components/Mine.vue";
    9. export default {
    10. name: "App",
    11. data() {
    12. return {
    13. name: {
    14. sex: "dr",
    15. age: "34",
    16. class: "de",
    17. },
    18. };
    19. },
    20. components: {
    21. Mine,
    22. },
    23. };
    24. </script>
    25. <style></style>