Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yangliguo7 opened this issue Nov 30, 2021 · 4 comments · Fixed by #5022
Labels
🐞 bug Something isn't working

Comments

@yangliguo7
Copy link

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

@yangliguo7
Copy link
Author

yangliguo7 commented Nov 30, 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

@LinusBorg
Copy link
Member

LinusBorg commented Nov 30, 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.

@yangliguo7
Copy link
Author

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

@LinusBorg LinusBorg reopened this Nov 30, 2021
@LinusBorg
Copy link
Member

Seems we expose the wrong proxy here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.