My approach involves using config data to simultaneously affect the status of all components. I achieve this by importing the config object from the same JavaScript file and incorporating it into each component's data.
It appears to work seamlessly, as any changes made to the config are reflected across all components in real-time. However, I have not come across this method being used in other projects, which raises concerns about its unconventional nature.
Will this unorthodox approach lead to any potential problems in the long run?
Config data:
export default {
status: {
name: 'xxx',
sex: 'male'
}
}
All components:
import config from './config'
data() {
return {
config
}
}
By invoking a method from any one of the components, all components are affected:
methods: {
setUser() {
this.config.state.name = 'yyy'
}
}
Thank you for taking the time to read this.