vue中样式的典型操作(:class,:style)

1 <template> 2 <div class="home-wrapper"> 3 <div class="home-top">this is from Home.vue</div> 4 <!--num>10,背景颜色红色,否则橙色--> 5 <div class="test" :class="num>10? bgColor1: bgColor2">this is a test,num is : {{num}}</div> 6 <button @click="changeNum">click to change num</button> 7 <div class="test2" :style="{fontSize: fontSize+ 'px'}">this is test2</div> 8 <button @click="changeTest2FontSize">click to change fontSize</button> 9 </div> 10 </template> 11 12 <script> 13 export default { 14 name: 'Home', 15 data () { 16 return { 17 num: '', 18 bgColor1: 'bgColor1', 19 bgColor2: 'bgColor2', 20 fontSize: 10 21 } 22 }, 23 methods: { 24 changeNum () { 25 this.num = Math.floor(Math.random() * 20) 26 console.log(this.num) 27 }, 28 changeTest2FontSize () { 29 if (this.fontSize < 30) { 30 this.fontSize = 30 31 } else { 32 this.fontSize = 15 33 } 34 } 35 } 36 } 37 </script> 38 39 <style lang="scss" scoped> 40 .home-wrapper{ 41 width: 80%; 42 display: flex; 43 align-items: center; 44 flex-direction: column; 45 .home-top{ 46 width: 300px; 47 height: 100px; 48 } 49 .bgColor1{ 50 background-color: red; 51 } 52 .bgColor2{ 53 background-color: orange; 54 } 55 .test{ 56 width: 300px; 57 height: 200px; 58 } 59 } 60 61 </style>
代码如上!
当时光不再,莫空留遗恨!
分类:
vue.js
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· dotnet 源代码生成器分析器入门
· 官方的 MCP C# SDK:csharp-sdk
· 一款 .NET 开源、功能强大的远程连接管理工具,支持 RDP、VNC、SSH 等多种主流协议!
· 一文搞懂MCP协议与Function Call的区别
· 一次Java后端服务间歇性响应慢的问题排查记录