How to pass properties to setup through a function? #9000
Answered
by
Domain
Domain
asked this question in
Help/Questions
-
I want to define the following function: const defineCmd = (tmpl, ...properties) => {
return defineComponent({
template: tmpl,
setup() {
return {
...properties
}
},
components: {
cmd
}
}
);
}; And use it like this: import { Constant } from "../../configs/constant.js";
defineCmd(`<cmd :label="$t('commands.status')" color="positive" :url="Constant.URL.Servers"" />`, Constant) But the Constant object cannot be recognized: If I change the definition to this: import { Constant } from "../../configs/constant.js";
const defineCmd = (tmpl) => {
return defineComponent({
template: tmpl,
setup() {
return {
Constant
}
},
components: {
cmd
}
}
);
}; It works. But I don't want to hard code the properties. How can I pass the properties to setup? |
Beta Was this translation helpful? Give feedback.
Answered by
Domain
Aug 17, 2023
Replies: 1 comment
-
OK, I figure it out. Just pass the properties as a whole object! const defineCmd = (tmpl, properties) => {
return defineComponent({
template: tmpl,
setup() {
return properties;
},
components: {
cmd
}
}
);
};
defineCmd(`<cmd :label="$t('commands.status')" color="positive" :url="Constant.URL.Servers"" />`, {Constant}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Domain
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, I figure it out. Just pass the properties as a whole object!