JavaScript/vue.js/watch:修订间差异
来自康健生活
< JavaScript | vue.js
| 第1行: | 第1行: | ||
== VUE 3 == | == VUE 3 == | ||
=== 多参数监听 === | |||
<syntaxhighlight lang="html"> | <syntaxhighlight lang="html"> | ||
<script setup> | <script setup> | ||
| 第9行: | 第11行: | ||
} | } | ||
) | ) | ||
</script></syntaxhighlight> | |||
=== 停止监听 === | |||
<syntaxhighlight lang="html"> | |||
<script> | |||
export default defineComponent({ | |||
// ... | |||
watch: { | |||
foo(_new, _old) { | |||
// ... | |||
} | |||
}, | |||
setup(props, vm) { | |||
// ... | |||
vm.$watch("count")(); | |||
} | |||
// ... | |||
}) | |||
</script></syntaxhighlight> | </script></syntaxhighlight> | ||
2025年3月18日 (二) 13:50的版本
VUE 3
多参数监听
<script setup>
import { ref } from 'vue'
watch(
() => [foo, bar],
(_new, _old) => {
// ...
}
)
</script>
停止监听
<script>
export default defineComponent({
// ...
watch: {
foo(_new, _old) {
// ...
}
},
setup(props, vm) {
// ...
vm.$watch("count")();
}
// ...
})
</script>
No categories