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