• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
keenjade
博客园    首页    新随笔    联系   管理    订阅  订阅
【vue】 点击切换字体颜色
  <!-- 点击添加字体颜色 -->
    <style scoped>
        .active {
            color: red;
        }
    </style>
    <div id="app-2">
        <ul>
            <li v-for="(item,index) in movies" :class="{active:index == isSelect}" @click="bindColor(index)">
                {{index}}:{{item}}</li>
        </ul>
    </div>
    <script>
        new Vue({
            el: "#app-2",
            data: {
                isSelect: false,
                color: 'red',
                movies: ['海贼王', '火影', '死神', '天空之城',]
            },
            methods: {
                bindColor: function (index) {
                    console.log(index)
                    this.isSelect = index
                }
            }
        })
    </script>
posted on 2020-03-04 10:33  keenjade  阅读(5137)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3