console
Vue.use(VueCompositionAPI);
const { watch, defineComponent, ref, computed } = VueCompositionAPI;
const Component = defineComponent({
template: '<button @click="addNum">开始死循环</button>',
setup() {
const num = ref(1);
const num2 = ref(2);
function addNum() {
num.value++;
}
watch(num, () => {
num2.value++;
console.log('num changed');
});
watch(num2, () => {
console.log('num2 changed');
})
watch(num, () => {
throw new Error('err');
});
return {
addNum,
};
}
})
new Vue({
el: '#app',
render: h => h(Component)
});
<div id="app"></div>