Vue组件的基本

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件的基本使用</title>
</head>

<body>
    <div id='app'>
        <button-counter></button-counter>
        <button-counter></button-counter>
        <button-counter></button-counter>
    </div>
</body>
<script type="text/javascript" src="../js/vue.js"></script>
<script>
    //组件注册
    Vue.component('button-counter', {
        data: function () {
            return {
                count: 0
            }
        },
        template: '<button @click="handle">点击了{{count}}</button>',
        methods: {
            handle: function () {
                this.count += 1;
            }
        }

    })
    var vm = new Vue({
        el: '#app',
        data: {

        }
    });
</script>

</html>

posted @ 2021-09-08 23:06  丁帅帅dss  阅读(36)  评论(0)    收藏  举报