Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Created October 3, 2020 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cursosdesarrolloweb/1963216136593da840dd0b497be70c51 to your computer and use it in GitHub Desktop.
Save cursosdesarrolloweb/1963216136593da840dd0b497be70c51 to your computer and use it in GitHub Desktop.
Vue.component('methods', {
data () {
return {
name: 'Israel',
surname: 'Parra'
}
},
computed: {
fullName () {
return `${this.name} ${this.surname}`;
}
},
methods: {
helloUser () {
alert(this.fullName);
}
},
template: `
<div>
<h2>Ejecutar métodos con Vue 2</h2>
<p @click="helloUser">Pulsa aquí para ejecutar el método helloUser</p>
</div>
`
});
app.component('methods', {
setup() {
const name = ref("Israel");
const surname = ref("Parra");
const fullName = computed(() => {
return `${name.value} ${surname.value}`;
});
const helloUser = () => {
alert(`Hola ${fullName.value}`);
}
return { helloUser };
},
template: `
<h2>Ejecutar métodos con Vue 3</h2>
<p @click="helloUser">Pulsa aquí para ejecutar el método helloUser</p>
`
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment