码迷,mamicode.com
首页 > 其他好文 > 详细

组件-配置组价

时间:2018-01-30 20:01:26      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:meta   vue.js   one   ++   his   log   turn   oct   gpo   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .liked{
            background-color: red;
        }
    </style>
</head>
<body>
<div id="app">
    <like></like>
</div>

<!--<template id="like-compoent-top">-->
    <!--<button :class=‘{liked:liked}‘ @click=‘toggle_like()‘>赞{{like_count}}</button>-->
<!--</template>-->

<script src="../lib/vue.js"></script>
<script src="js/main.js"></script>
</body>
</html>
Vue.component("like",{
    template:`
        <button :class=‘{liked:liked}‘ @click=‘toggle_like()‘>赞{{like_count}}</button>
    `,
    // template:"#like-compoent-top",
    data:function () {
        return {
            like_count:10,
            liked:false
        }
    },
    methods:{
        toggle_like:function () {
            if (!this.liked){
                this.like_count++;
            }else{
                this.like_count--;
            }
            this.liked = !this.liked
        }
    }
});

new Vue({
    el:"#app"
});

 

组件-配置组价

标签:meta   vue.js   one   ++   his   log   turn   oct   gpo   

原文地址:https://www.cnblogs.com/52-qq/p/8386311.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!