The custom directive is in the production environment, and the function under instance is missing
Version
3.0.0
Reproduction link
Steps to reproduce
npm run serve npm run serve:prd
What is expected?
The button should be triggered in both environments
What is actually happening?
In dev environment, button be triggered
the code likeļ¼
< template >
< button v-operate:add >button< /button >
< /template >
<script setup>
const add = () =>{
console.log('click trigger')
}
</script>
app.directive("operate", {
mounted(el, binding) {
const { arg, instance, value } = binding;
console.log(binding);
const { param } = value || {};
if (!instance?.[arg]) {
console.log('not exist ')
return;
}
el.addEventListener('click', instance[arg].bind(instance, param));
},
})
There is no add event defined by me on instance, but it exists in dev environment
<script setup>
const add = () =>{
console.log('click trigger')
}
defineExpose({
add,
})
</script>
See: https://v3.vuejs.org/api/sfc-script-setup.html#defineexpose
The source of the difference in behavior is the same as #4980 so I'll close this one as a duplicate.