Home  >  Article  >  Web Front-end  >  How to implement click in vue

How to implement click in vue

coldplay.xixi
coldplay.xixiOriginal
2020-11-24 15:59:405192browse

How to implement click in vue: first create a new HTML code page; then create a [

] tag on this code page; then create a click event function; finally add a vue click event to the click button , and save the html code.

How to implement click in vue

The operating environment of this tutorial: Windows 7 system, Vue version 2.9.6. This method is suitable for all brands of computers.

How to implement click in vue:

1. Create a new html code page, and then create a <div># on this code page. ## tag, and add an id to the <div> tag at the same time as app, and then create a click button in this <div> tag. <pre class="brush:php;toolbar:false">&lt;div id=&quot;app&quot;&gt; &lt;input type=&quot;button&quot; value=&quot;点击我&quot; /&gt; &lt;/div&gt;</pre>2. Introduce the vue.js file, create a <p><script><code> tag, and use new Vue({})<code> in this tag to create an instance of vue change. <pre class="brush:php;toolbar:false">&lt;script type=&quot;text/javascript&quot; src=&quot;js/vue.js&quot; &gt;&lt;/script&gt; &lt;script&gt; var app = new Vue({ el:&quot;#app&quot; }) &lt;/script&gt;</pre></script></p>3. Create a click event function. Create a method to trigger the vue click event in the methods given on the vue official website (in the case, an alert popup pops up when the click event is triggered). <p><pre class="brush:php;toolbar:false">methods:{ test:function(){ //vue的点击触发事件 alert(&quot;完成vue的点击事件&quot;) } }</pre></p>4. Add a vue click event to the click button. Just add <p>@click="test"<code> in the click button label.

<div id="app">
    <input type="button" value="点击我" @click="test"/>
</div>

5. Save the html code, and then open it with a browser. Click the button event on the browser page. At this time, you can see an alert pop-up box pop up on the browser, indicating that the vue click event has been successfully executed.

How to implement click in vue

All codes:

<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="UTF-8">
        <title>vue点击事件</title>
    </head>
    
    <body>
        <div id="app">
            <input type="button" value="点击我" @click="test" />
        </div>
        <script type="text/javascript" src="js/vue.js"></script>
        <script>
            var app = new Vue({
                el: "#app",
                methods: {
                    test: function() { //vue的点击触发事件
                        alert("完成vue的点击事件")
                    }
                }
            })
        </script>
    </body>
</html>

Related free learning recommendations:

JavaScript (video)

The above is the detailed content of How to implement click in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to prevent div from displaying in jqueryNext article:How to prevent div from displaying in jquery

Related articles

See more