vue中样式的典型操作(:class,:style)
<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)的更多相关文章
- vue_music:排行榜rank中top-list.vue中样式的实现:class
排行榜的歌曲列表,根据排名渲染不同的样式,同时需要考虑分辨率的2x 3x图 不同的样式--:class 考虑分辨率的2x 3x图--需要在stylu中的mixin中bgImage根据屏幕分辨率选择图片 ...
- Vue中对data的操作
1. {{a}} var vm = new Vue({ el: '#app', data: { a: { a: 1, b: 2 } } }) vm.a.c = 'sadoisad' // 按理说是 ...
- 09.vue中样式-style
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【转】vue中样式被覆盖的问题,vue中的style不生效
转载:http://www.cnblogs.com/shangjun6/p/11416054.html 在我们引入外部的样式时,发现自己无论如何都改不了外部的样式,自己的样式老被覆盖,究其原因还是我们 ...
- vue 中样式的绑定
1.class的对象绑定 //对应的css <style> .active { color: red; } </style> <!--html 对应的代码--> & ...
- vue中,class、内联style绑定、computed属性
1.绑定Class ①对象语法 <li :class="{ 'active': activeIdx==0 }" @click="fnClickTab(0)" ...
- 08.vue中样式-class
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue中关于dom的操作
mounted 个人理解为DOM结构准备就绪了,可以开始加载vue数据了, 挂载点,配合使用 mounted:function(){ this.$nextTick(function(){ //this ...
- vue学习(八) vue中样式 class 定义引用
//style<style> .red{ color:red; } .thin{//字体粗细 font-weight:200 } .italic{//字体倾斜 font-style:ita ...
随机推荐
- 第一篇 Flask初始
Python 现阶段三大主流Web框架 Django Tornado Flask 对比 1.Django 主要特点是大而全,集成了很多组件,例如: Models Admin Form 等等, 不管你用 ...
- 使用Object.prototype.toString.call()方法精确判断对象的类型
在JavaScript里使用typeof判断数据类型,只能区分基本类型,即:number.string.undefined.boolean.object. 对于null.array.function. ...
- [LeetCode] Number of Lines To Write String 写字符串需要的行数
We are to write the letters of a given string S, from left to right into lines. Each line has maximu ...
- 一键安装metasploit(linux,os x)
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit- ...
- bootstrap网格设置等高度
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...
- Express全系列教程之(八):session的基本使用
一.关于session session是另一种记录客户状态的机制,与cookie保存在客户端浏览器不同,session保存在服务器当中:当客户端访问服务器时,服务器会生成一个session对象,对象中 ...
- std unorder_map insert 和 emplace的区别
std::unordered_map<int, int > map; map.insert(std::make_pair(, )); map.insert(std::make_pair(, ...
- react-router@4.0 使用和源码解析
如果你已经是一个正在开发中的react应用,想要引入更好的管理路由功能.那么,react-router是你最好的选择~react-router版本现今已经到4.0.0了,而上一个稳定版本还是2.8.1 ...
- cygwin的sh: line 15: $'\r': command not found错误
安装dos2unix工具,转换一下sh文件即可 apt-cyg install dos2unix dos2unix xxx.sh
- 自学传说中的php接口编写
一个前端学php,感觉不可思议,但实际上面试中都会问你后台会不会.这时候php就派上用场了. 下面的是我自己百度研究的一个些心得分享一下: html代码 <!DOCTYPE html> & ...