vue学习笔记

时间:2020-04-28
本文章向大家介绍vue学习笔记,主要包括vue学习笔记使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

例1 el使用

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>New Web Project</title>
        <script src="vue.js"></script>
    </head>
    <body>
        <div id="app">
            <h1>当前计数器:{{counter}}</h1>
            <button v-on:click='add'>+</button>
            <button @click='sub'>-</button>
        </div>
        
    </body>
    <script>
        const app = new Vue({
            el:'#app',
            data:{
                counter:0
            },
            methods:{
                add:function(){
                    this.counter = this.counter+3
                },
                sub:function(){
                    this.counter--
                }
            }
        })
    </script>
</html>
View Code

例2 template使用

    <body>
        <div id="app">
            <p>
                被替代
            </p>
        </div>
        <script id="tpl" type="x-template">
            <div class='tpl'>
                   
                <p>
                    我来了
                </p>
            </div>
        </script>
        <script type="text/javascript">
            var vm = new Vue({
               el : '#app',
               template : '#tpl'
             });
        </script>
    </body>
View Code

原文地址:https://www.cnblogs.com/polax/p/12794762.html