vue切换样式
Posted wntd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue切换样式相关的知识,希望对你有一定的参考价值。
在vue中使用事件来切换绑定的class样式,在vue-cli脚手架中的Home.vue中
<template> <div id="main"> <li v-for="v in news"> <span :class="v.status ? ‘success‘ : ‘error del‘">{{v.title}}</span> <button @click="switchState(v,true)" v-if="!v.status">恢复</button> <button @click="switchState(v,false)" v-if="v.status">删除</button> </li> </div> </template> <script> export default{ data(){ return { news:[ {title:‘rock‘,status:true}, {title:‘cena‘,status:true}, {title:‘randy‘,status:true} ] }; }, methods:{ switchState(v,status){ v.status = status; } } } </script> <style> .success{ color:green; } .error{ color:red; } .del{ text-decoration:line-through; } </style>
效果如下:
以上是关于vue切换样式的主要内容,如果未能解决你的问题,请参考以下文章