JavaScript/vue.js/watch:修订间差异
来自康健生活
| (未显示同一用户的3个中间版本) | |||
| 第1行: | 第1行: | ||
== VUE 3 == | == VUE 3 == | ||
=== 多参数监听 === | |||
<syntaxhighlight lang="html"> | <syntaxhighlight lang="html"> | ||
<script setup> | <script setup> | ||
| 第10行: | 第12行: | ||
) | ) | ||
</script></syntaxhighlight> | </script></syntaxhighlight> | ||
=== 停止监听 === | |||
<syntaxhighlight lang="html"> | |||
<script> | |||
import { getCurrentInstance } from 'vue' | |||
export default defineComponent({ | |||
// ... | |||
watch: { | |||
foo(_new, _old) { | |||
// ... | |||
} | |||
}, | |||
setup(props, vm) { | |||
const { proxy } = getCurrentInstance() | |||
// ... | |||
proxy.$watch("foo")(); | |||
} | |||
// ... | |||
}) | |||
</script></syntaxhighlight> | |||
=== onTrigger === | |||
=== watchEffect === | |||
<syntaxhighlight lang="html5"> | |||
<script> | |||
import { watchEffect } from 'vue' | |||
// ... | |||
setup() { | |||
watchEffect(() => { | |||
console.log('count changed to', count.value); | |||
}); | |||
// ... | |||
</script> | |||
</syntaxhighlight> | |||