Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Last active Oct 3, 2020
Embed
What would you like to do?
const Profile = {
install: (Vue, options) => {
const { skills } = options;
Vue.prototype.$profile = (name, age) => {
return `Mi nombre es ${name}, tengo ${age} años y trabajo de ${skills}`;
}
}
};
Vue.use(Profile, {
skills: 'programador e instructor en Cursosdesarrolloweb'
});
const createProfile = config => ({
name: config.name,
age: config.age,
skills: config.skills,
$skill(key) {
return this.skills[key];
}
});
const profileSymbol = Symbol();
function provideProfile(profileConfig) {
const profile = createProfile(profileConfig);
provide(profileSymbol, profile);
}
function useProfile() {
const profile = inject(profileSymbol);
if (!profile) throw new Error("Debes ejecutar provideProfile para utilizar este plugin");
return profile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment