Subscribe on changes!

The custom directive is in the production environment, and the function under instance is missing

avatar
Nov 30th 2021

Version

3.0.0

Reproduction link

github.com

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

avatar
Nov 30th 2021

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

avatar
Nov 30th 2021
<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.

avatar
Nov 30th 2021

@LinusBorg I've used this method before, but it doesn't work

avatar
Nov 30th 2021

Seems we expose the wrong proxy here.