Setting Quasar component props globally to a default value #10151
hedgehogs-mind
started this conversation in
Show and Tell
Replies: 2 comments 2 replies
-
or more simple in a js file export const options = {
btn: {
color: 'primary',
...
},
...
} in a component import { options } from 'options file'
data () {
return {
options
}
} <q-btn v-bind="options.btn" ... /> |
Beta Was this translation helpful? Give feedback.
1 reply
-
wrt Quasar-V2 have a look at #8761 (comment) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Imagine you want to change the default prop values of a component prop globally.
Imagine the following requirements: Per default,
<q-btn color="primary" outline rounded no-caps :ripple="false" />
and<q-input outlined rounded />
To be mentioned: Of course, we could create a custom component for our default design, but we wanted to keep our code as Quasar-clean as possible (and keep autocompletion for props if our IDE detects Quasar components). And thus the requirement was, that we still use the tags
q-btn
respectivelyq-input
.Here is a way nr. 1 I found, to achieve this without a lot of effort (although I don't know if it's good or bad):
quasar.conf.js
.{component}.options.props.{propName}.default = {newDefaultValue}
Example for the requirements listed earlier:
Evaluation:
+
: normal component tags can still be used+
: super simple to set up and configure- / ?
: is it allowed to modifyoptions.props
?What do you think of it? Do you think it's okay to modify
options.props
of an imported component?We did not find a solution like this for Vue somewhere else.
Altneratively: We thought of wrapping Quasar components and replacing the components in the global registry with our wrapper (kinda like a monkey patch). This would also allow to define default classes for components.
Exchanging the components via
Vue.component(...)
did not work. Until now, I also did not really found out, how and where Quasar registers its components. I only know they are registered upon the first step (according to the boot files doc page).As a really bad workaround I created a global mixin, which replaces certain components with monkey patch components before mount.
Code snippets
Boot file:
monkeyPatches(/index.js):
PatchedQBtn.vue (uses a template) – prop defaults set and some default classes!:
PatchedQInput.vue (uses
extends
) – only prop defaults set:Evaluation:
+
: allows default classes to be defined–
: more complex–
: separate files needed–
: Current implementation: Component exchange will performed upon each mount!_What do you think of this solution?
Beta Was this translation helpful? Give feedback.
All reactions