当前位置: 首页 > news >正文

东莞做网站微信巴巴成都网络推广公司

东莞做网站微信巴巴,成都网络推广公司,域名代备案,深圳市企业网站建设Class数据绑定 数据绑定的一个常见需求场景是操作CSS class列表,因为class是attribute(属性),我们可以和其他attribute一样使用v-bind 将它们和动态的字符串绑定。但是,在处理比较复杂的绑定时,通过拼接生…

Class数据绑定

数据绑定的一个常见需求场景是操作CSS class列表,因为class是attribute(属性),我们可以和其他attribute一样使用v-bind 将它们和动态的字符串绑定。但是,在处理比较复杂的绑定时,通过拼接生成字符串是麻烦且容易出错的。因此,Vue 专门为class 的v-bind 用法提供了特殊的功能增强。除了字符串外,表达式的值也可以是数组或对象。

绑定对象Object

<template>
<h3>class数据绑定</h3>
<hr>
<div :class="{active:isActive,'text-danger':hasError}">isActive</div>
<button @click="exchage">切换</button></template>
<script>export default {
data(){return{isActive:true,hasError:true}
},
methods:{exchage(){this.isActive=!this.isActive}
}
}</script>
<style scoped>
.active{color:red;
}
</style>

运行结果
未切换前:
在这里插入图片描述
切换后:
在这里插入图片描述

多个对象绑定

<template>
<h3>class数据绑定</h3>
<hr>
<div :class="classObject">isActive</div>
<button @click="exchage">切换</button></template>
<script>export default {
data(){return{classObject:{active:true,'text-danger':true}}
},
methods:{exchage(){this.classObject.active = !this.classObject.active}
}
}</script>
<style scoped>
.active{color:rgb(132, 0, 255);font-size: large;
}
</style>

运行结果:
切换前:
在这里插入图片描述
切换后:
在这里插入图片描述

数组绑定

<template><h3>class数据绑定</h3><hr><div :class="[activeClass,errorClass]">isActive</div></template><script>export default {data(){return{activeClass: 'active',errorClass:'text-danger'}},}</script><style scoped>.active{color:red;}</style>

运行结果:
在这里插入图片描述
如果你想在数组中渲染某个class,你可以使用三元表达式。

<template><h3>class数据绑定</h3><hr><div :class="[isActive ? 'active' : '']">isActive</div><button @click="exchage">切换</button></template><script>export default {data(){return{isActive:true,}},methods:{exchage(){this.isActive=!this.isActive}}}</script><style scoped>.active{color:red;}</style>

运行结果:
在这里插入图片描述
切换:
在这里插入图片描述
数组和对象

<template><h3>class数据绑定</h3><hr><div :class="[{'active':isActive},errorClass]">isActive</div><button @click="exchage">切换</button></template><script>export default {data(){return{isActive:true,errorClass:"text-danger"}},methods:{exchage(){this.isActive=!this.isActive}}}</script><style scoped>.active{color:red;}</style>

运行结果:
在这里插入图片描述

温馨提示:
数组和对象的嵌套过程中,只能数组嵌套对象,不能反其道而行。

http://www.hkea.cn/news/738550/

相关文章:

  • 北京做网站建设的公司哪家好手机怎么创建网站
  • winforms做网站注册百度账号
  • 玉泉路网站建设营销培训课程有哪些
  • 渭南做网站费用搜索引擎排名优化是什么意思
  • 做网站开发需要学什么软件微信公众平台开发
  • 网站整体营销方案网络营销的特点是什么?
  • 国内知名的网站建设公司有哪些百度指数专业版app
  • 画画外包网站如何推广一个网站
  • 互联网公司响应式网站深圳google推广
  • 深圳网站设计哪好什么推广平台比较好
  • 打开英文网站字体不对教程seo推广排名网站
  • 昭通市建设局网站太原百度关键词优化
  • 个人建网站允许吗seo职位要求
  • 环保网站设计网络营销优化推广
  • 网页设计网站制作公司冯耀宗seo视频教程
  • 怎么用路由器做网站百度指数平台官网
  • 济南做网站互联网公司有哪些seo是什么公司
  • 辛集seo网站优化价格许昌网站seo
  • 网站建设后期维护百度快速收录技术
  • 网站建设中的推广工作seo学校培训
  • 上海专业网站建设网百度搜索推广开户
  • 做学校网站素材图片合肥seo代理商
  • 真题真做报名网站淘宝搜索关键词排名
  • 免费的黄冈网站有哪些平台?培训行业seo整站优化
  • 寿县住房与城乡建设局网站真正免费的网站建站平台
  • 常德seo招聘网站seo站长工具
  • 网站开发多久完成俄罗斯搜索引擎yandex推广入口
  • 漳州做网站建设建网站免费
  • 网站建设服务上海广州软文推广公司
  • 做一个网站app需要多少钱web制作网站的模板