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切换样式的主要内容,如果未能解决你的问题,请参考以下文章

网页换肤效果 系统界面切换皮肤样式

用Vue实现点击一个按钮,实现切换样式的效果

05《Vue 入门教程》Vue 动态样式绑定

vue的v-show指令实现2种样式切换效果

vue切换样式

vue点击切换样式,点击切换地址栏,点击显示或者隐藏