前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >vue中样式的典型操作(:class,:style)

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

作者头像
用户1149564
发布2018-11-29 16:42:08
9800
发布2018-11-29 16:42:08
举报
文章被收录于专栏:Micro_awake webMicro_awake web
 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>

代码如上!

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-10-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档