要修改父组件的值,可以通过props和事件来实现。
// 父组件
<template>
  <div>
    <ChildComponent :value="parentValue" @updateValue="updateValue" />
    <p>父组件的值: {{ parentValue }}</p>
  </div>
</template>
<script>
  import ChildComponent from './ChildComponent.vue';
  export default {
    data() {
      return {
        parentValue: '初始值',
      };
    },
    methods: {
      updateValue(newValue) {
        this.parentValue = newValue;
      },
    },
    components: {
      ChildComponent,
    },
  };
</script>
// 子组件
<template>
  <div>
    <input v-model="value" @input="updateParentValue" />
    <p>子组件的值: {{ value }}</p>
  </div>
</template>
<script>
  export default {
    props: {
      value: String,
    },
    methods: {
      updateParentValue() {
        this.$emit('updateValue', this.value);
      },
    },
  };
</script>
// 父组件
<template>
  <div>
    <ChildComponent @updateValue="updateValue" />
    <p>父组件的值: {{ parentValue }}</p>
  </div>
</template>
<script>
  import ChildComponent from './ChildComponent.vue';
  export default {
    data() {
      return {
        parentValue: '初始值',
      };
    },
    methods: {
      updateValue(newValue) {
        this.parentValue = newValue;
      },
    },
    components: {
      ChildComponent,
    },
  };
</script>
// 子组件
<template>
  <div>
    <button @click="updateParentValue">更新父组件的值</button>
  </div>
</template>
<script>
  export default {
    methods: {
      updateParentValue() {
        this.$emit('updateValue', '新的值');
      },
    },
  };
</script>
以上示例演示了两种方法来修改父组件的值,你可以根据实际情况选择其中一种来实现。