<!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 >-->
    <!--<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"
});

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2022-01-19
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-11-06
相关资源
相似解决方案