I'm developing a couple of Vue apps using single file components. I find quite a few of my components require common config information, for example an object containing delivery methods which I might define like this:
const DeliveryMethods = {
DELIVERY: "Delivery",
CARRIER: "Carrier",
COLLATION: "Collation",
CASH_AND_CARRY: "Cash and carry"
}
What is the cannonical way to make that available to my components? At the moment, I have done it with a file 'config.js', as below:
export default {
DeliveryMethods: {
DELIVERY: "Delivery",
CARRIER: "Carrier",
COLLATION: "Collation",
CASH_AND_CARRY: "Cash and carry"
}
}
In my components where I need it, I have import config from 'src/config.js'
, and where I want to use one of these, I'll refer to e.g., config.DeliveryMethods.CASH_AND_CARRY
. This seems to me rather long-winded and repetitive, though, and I'd prefer to be able to use just DeliveryMethods.CASH_AND_CARRY
instead of config.DeliveryMethods.CASH_AND_CARRY
.
What is the canonical way to based on js lint and/or the jquery style guide? Are there any other authorities to consider?