惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
博客园 - 叶小钗
N
Netflix TechBlog - Medium
罗磊的独立博客
量子位
MyScale Blog
MyScale Blog
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
B
Blog
腾讯CDC
爱范儿
爱范儿
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
雷峰网
雷峰网
G
Google Developers Blog
Google DeepMind News
Google DeepMind News

mafeifan 的编程技术分享

mafengwo-mp3-downloader | mafeifan 的编程技术分享 示例页面 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 查看 default namespace 下的 default service account名称 mafeifan 的编程技术分享 检查日志 | mafeifan 的编程技术分享 bridge fdb show dev flannel.1 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享
mafeifan 的编程技术分享
2026-01-16 · via mafeifan 的编程技术分享

.sync修饰符本质上是语法糖 用于子组件可以修改父组件。

传统上可以这样做:

子组件,发射事件

<template>
  <div class="child" style="border: 1px dotted red">
    <input type="text" @input="handleOuter" v-model="innerText">
    <div>等待被内部组件修改</div>
  </div>
</template>

<script>
export default {
  name: 'Child',
  data () {
    return {
      innerText: '',
    }
  },
  methods: {
    // 修改内容时发射事件,然后在父组件接收
    handleOuter(e) {
      console.log(e);
      this.$emit('update:outer', this.innerText);
    },
  },
}
</script>

父组件:

<template>
  <div style="border: 1px dotted blue">
    <h1>父子组件数据传递</h1>
    <h3>Parent:</h3>
    <div v-text="fromInner"></div>
    <h3>Child:</h3>
   <!-- 接收事件并实时更新父组件的 fromInner 属性 -->
    <i-child @update:outer="val => fromInner = val"/>
  </div>
</template>
<script>
import Child from './child';
export default {
  name: 'Parent',
  components: {
    'i-child': Child
  },
  data () {
    return {
      fromInner: '',
    }
  },
  methods: {
  },
}
</script>

使用 .sync后 <i-child :outer.sync="fromInner"/>

需要注意的是sync要写在子组件上面