<template>
<div class="home-wrapper">
<div class="home-top">this is from Home.vue</div>
<!--num>10,背景颜色红色,否则橙色-->
<div class="test" :class="num>10? bgColor1: bgColor2">this is a test,num is : {{num}}</div>
<button @click="changeNum">click to change num</button>
<div class="test2" :style="{fontSize: fontSize+ 'px'}">this is test2</div>
<button @click="changeTest2FontSize">click to change fontSize</button>
</div>
</template> <script>
export default {
name: 'Home',
data () {
return {
num: '',
bgColor1: 'bgColor1',
bgColor2: 'bgColor2',
fontSize: 10
}
},
methods: {
changeNum () {
this.num = Math.floor(Math.random() * 20)
console.log(this.num)
},
changeTest2FontSize () {
if (this.fontSize < 30) {
this.fontSize = 30
} else {
this.fontSize = 15
}
}
}
}
</script> <style lang="scss" scoped>
.home-wrapper{
width: 80%;
display: flex;
align-items: center;
flex-direction: column;
.home-top{
width: 300px;
height: 100px;
}
.bgColor1{
background-color: red;
}
.bgColor2{
background-color: orange;
}
.test{
width: 300px;
height: 200px;
}
} </style>

代码如上!

vue中样式的典型操作(:class,:style)的更多相关文章

  1. vue_music:排行榜rank中top-list.vue中样式的实现:class

    排行榜的歌曲列表,根据排名渲染不同的样式,同时需要考虑分辨率的2x 3x图 不同的样式--:class 考虑分辨率的2x 3x图--需要在stylu中的mixin中bgImage根据屏幕分辨率选择图片 ...

  2. Vue中对data的操作

    1. {{a}} var vm = new Vue({ el: '#app', data: { a: { a: 1, b: 2 } } })   vm.a.c = 'sadoisad' // 按理说是 ...

  3. 09.vue中样式-style

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 【转】vue中样式被覆盖的问题,vue中的style不生效

    转载:http://www.cnblogs.com/shangjun6/p/11416054.html 在我们引入外部的样式时,发现自己无论如何都改不了外部的样式,自己的样式老被覆盖,究其原因还是我们 ...

  5. vue 中样式的绑定

    1.class的对象绑定 //对应的css <style> .active { color: red; } </style> <!--html 对应的代码--> & ...

  6. vue中,class、内联style绑定、computed属性

    1.绑定Class ①对象语法 <li :class="{ 'active': activeIdx==0 }" @click="fnClickTab(0)" ...

  7. 08.vue中样式-class

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. vue中关于dom的操作

    mounted 个人理解为DOM结构准备就绪了,可以开始加载vue数据了, 挂载点,配合使用 mounted:function(){ this.$nextTick(function(){ //this ...

  9. vue学习(八) vue中样式 class 定义引用

    //style<style> .red{ color:red; } .thin{//字体粗细 font-weight:200 } .italic{//字体倾斜 font-style:ita ...

随机推荐

  1. Redis新接触

    一.redis简介 redis即Remote Dictionary Server,是一个key—value存储系统. 二.优点 1.redis支持的存储类型较多,如String.List.Hash.s ...

  2. 【转】Spring总结以及在面试中的一些问题

    [转]Spring总结以及在面试中的一些问题. 1.谈谈你对spring IOC和DI的理解,它们有什么区别? IoC Inverse of Control 反转控制的概念,就是将原本在程序中手动创建 ...

  3. python语法_字符串

    字符串 a = 'asdb' #双引号和打印号没区别, 操作 "abc"*2 打印两遍"abc"  #字符串 加* 重复打印字符串 “abc”[2:1] #切片 ...

  4. Tensorflow Chapter-6

    |--子节点 |--单位节点矩阵:长宽为1,深度不限 |--多维度的二维卷积,和之前的理解不一样:应该是每个通道都要计算在下一层的每个节点上:2*2*3,f=1*1*5 -> 2*2*3*5个参 ...

  5. HDU 6321 Dynamic Graph Matching

    HDU 6321 Dynamic Graph Matching (状压DP) Problem C. Dynamic Graph Matching Time Limit: 8000/4000 MS (J ...

  6. PHP的运算符

    1.算术运算符 2.赋值运算符 基本的赋值运算符是“=”. (1)引用赋值 PHP 支持引用赋值,使用“$var = &$othervar;”语法.引用赋值意味着两个变量指向了同一个数据,没有 ...

  7. js JQuery 获取元素和遍历

    用户名<input class="yonghu" type="text" id="user" name="u" / ...

  8. tomcat 启动方式

    <?xml version="1.0" encoding="UTF-8"?><Context docBase="wexin" ...

  9. JS判断字符串长度的5个方法(区分中文和英文)

    目的:计算字符串长度(英文占1个字符,中文汉字占2个字符) 方法一: 代码如下: String.prototype.gblen = function() {    var len = 0;    fo ...

  10. Java 线程池比较

    小结: 1. 高级面试题总结—线程池还能这么玩? - 这个时代,作为程序员可能要学习小程序 - CSDN博客https://blog.csdn.net/androidstarjack/article/ ...