[Vuejs]-Why Vue.js template can't interact it's script?

3👍

in vue you must write functions in the methods object and onclick == @click

<template>
        <button @click="someClickFunction();"></button>
    </template>

    <script>
        export default {
            name: "button-view",
            methods: {
              someClickFunction(){
                console.log("You've pressed the button");
              }
            }
        }
    </script>

    <style scoped>
    </style>

1👍

That’s because in vue, you don’t use the native onclick event.

Instead you use the

v-on:click

or the

@click

Better check the documentation. It is written very thoroughly
https://v2.vuejs.org/v2/guide/events.html

EDIT:
You also have error on your script. All functions must be declared inside the methods of the vue instance

👤keysl

Leave a comment