2

关于 Vue3 自定义组件双向绑定问题

 2 years ago
source link: https://www.v2ex.com/t/872868
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Vue.js

关于 Vue3 自定义组件双向绑定问题

  ciming · 1 小时 40 分钟前 · 341 次点击
<template>
  <div></div>
</template>

<script setup>
const emit = defineEmits(["update:modelValue"]);
const props = defineProps({
  modelValue: {
    type: Array,
    defualt: [],
  },
});

watch(
  () => props.modelValue,
  () => {
  	// 一些操作
  },
  {
    immediate: true,
  }
);

</script>

有没有办法,如果组件内部 emit 改变 modelValue 的值不触发组件内部 watch 监听,只有在父组件改变了传入的值才触发组件内部 watch 监听


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK