Share a method between components

Hello people,
I am trying to share a method between multiple components and this method should access an attribute from the parent component.
I am using VUE3, with script setup.
I tried with “extend” but I couldn’t find how to extend a component with script setup.
I don’t want to pass any parameter because in my real case I have many of them, too many.
Thank you very much for the support

//TheComponent.vue
<template>
    <div></div>
</template>
<script>
    import common from './Common.js';
    const x=7;
    common.print();
</script>

//Common.js
const common={
    print: function() {
        alert(x);
    }
  }
};
export default common;

It looks like a code smell. If you need to pass a variable to this method then just pass it. The best way to share logic in Vue 3 is to use composables. Just create common composable that accepts any arguments you need.

Could you post a more realistic example?

How many is too many? I’ve never heard of this as being an issue. If you have many parameters, then it often means they relate to something and restructuring your function could make things a lot more efficient, such as passing an object that holds all the context required for the function.

Basically, as @martinzeltin says, this is a code smell. Functions should accept parameters in order to perform their work - they should never rely on external sources.

data: () => ({
  myObj: { /* ... */ }
})

uncomposableMethod () {
  console.log(this.myObj)
  // Inefficient because it's tied to this context. It cannot be reused anywhere else.
}

composableMethod (data) {
  console.log(data)
  // Very efficient. Not tied to context. I can import this method anywhere I like and use it by simply passing it an argument
}

// e.g.
composableMethod(this.myObj)

Thank you for your answers.
I really just wanted to import the common.js file in such a way like it was part of that file. Basically I just want to store some code in 2 separate files.
I couldn’t find a way to do it.
If I can’t find a way, I will just use parameters.

Based on your example, it’s not possible. If it were, it would go completely against the purpose of modules; a self contained modular piece of code.

The only way you could achieve something like this would be to store and export the variable from common.js as well, but that’s just asking for trouble.