Vue学习(二):class与style绑定
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>class与style绑定</title>
<style type="text/css">
.static {
font-weight: bold;
} .class-a {
color: blue;
} .class-b {
font-size: 22px;
}
</style>
</head>
<body>
<!--1.绑定 HTML Class-->
<!--对象语法-->
<div id="example1" class="static" v-bind:class="{'class-a': isA, 'class-b': isB}">Hello Vue.</div>
<!--数组语法-->
<div id="example2" class="static" v-bind:class="[classA, classB]">Hello Vue.</div>
<div id="example3" class="static" v-bind:class="[classA, isB ? classB : '']">Hello Vue.</div> <!--2.绑定内联样式-->
<!--对象语法-->
<div id="example4" class="static" v-bind:style="{color: activeColor, 'font-size': fontSize + 'px'}">Hello Vue.</div>
<div id="example5" class="static" v-bind:style="styleObject">Hello Vue.</div>
<!--数组语法-->
<div id="example6" class="static" v-bind:style="[styleObjectA, styleObjectB]">Hello Vue.</div>
<script type="text/javascript" src="vue.min.js"></script>
<script>
// example 1
let vm1 = new Vue({
el: '#example1',
data: {
isA: true,
isB: false
}
});
console.log(vm1.$el); // example 2
let vm2 = new Vue({
el: '#example2',
data: {
classA: 'class-a',
classB: 'class-b'
}
});
console.log(vm2.$el); // example 3
let vm3 = new Vue({
el: '#example3',
data: {
classA: 'class-a',
classB: 'class-b',
isB: false
}
});
console.log(vm3.$el); // example 4
let vm4 = new Vue({
el: '#example4',
data: {
activeColor: 'red',
fontSize: '30'
}
});
console.log(vm4.$el); // example 5
let vm5 = new Vue({
el: '#example5',
data: {
styleObject: {
color: 'red',
fontSize: '25px'
}
}
});
console.log(vm5.$el); // example 6
let vm6 = new Vue({
el: '#example6',
data: {
styleObjectA: {
color: 'blue',
fontSize: '35px'
},
styleObjectB: {
'text-decoration': 'underline'
}
}
});
console.log(vm6.$el);
</script>
</body>
</html>
结果:
Vue学习(二):class与style绑定的更多相关文章
- day 82 Vue学习二之vue结合项目简单使用、this指向问题
Vue学习二之vue结合项目简单使用.this指向问题 本节目录 一 阶段性项目流程梳理 二 vue切换图片 三 vue中使用ajax 四 vue实现音乐播放器 五 vue的计算属性和监听器 六 ...
- day 81 Vue学习二之vue结合项目简单使用、this指向问题
Vue学习二之vue结合项目简单使用.this指向问题 本节目录 一 阶段性项目流程梳理 二 vue切换图片 三 vue中使用ajax 四 vue实现音乐播放器 五 vue的计算属性和监听器 六 ...
- 关于vue.js中class与style绑定的学习
练习代码: html: <!DOCTYPE html><html lang="en"><head> <meta charset=" ...
- Vue.2.0.5-Class 与 Style 绑定
Class 与 Style 绑定 数据绑定一个常见需求是操作元素的 class 列表和它的内联样式.因为它们都是属性 ,我们可以用v-bind 处理它们:只需要计算出表达式最终的字符串.不过,字符串拼 ...
- Vue教程:Class 与 Style 绑定(四)
绑定 HTML Class 对象语法 ①.添加单个class: <div v-bind:class="{ active: isActive }"></div> ...
- vue 学习二 深入vue双向绑定原理
vue双向绑定原理 请示总体来讲 就是为data的中的每个属性字段添加一个getter/seter属性 以此来追踪数据的变化,而执行这部操作,依赖的就是js的Object.defineProperty ...
- vue学习二:
vue的常用标签: 1.<router-link to=''>主要实现跳转链接功能,属性to='/'即是跳转到path为'/'的路径. 2.v-bind动态绑定指令,格式为:v-bind: ...
- 02.VUE学习二之数据绑定
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- Vue学习(二)-Vue中组件间传值常用的几种方式
版本说明:vue-cli:3.0 主要分为两类: 1.父子组件间的传值 2.非父子组件间的传值 1.父子组件间传值 父组件向子组件传值 第一种方式: props 父组件嵌套的子组件中,使用v-bind ...
- vue学习笔记 样式 class style(五)
使用v-bind数据绑定class和style,v-bind:class可以与传统的class属性共存,其中可以用{}设置多个class,根据条件判断的语法是class名:条件,带-的class名需要 ...
随机推荐
- Yii 判断是不是post方式提交的数据
一.在controller里判断提交是不是通过post方式: if(Yii::$app->request->isPost){ return true; }else{ return fals ...
- vue案列
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 消息中间件JMS(一)
1.JMS入门 1.1消息中间件 模块之间的依赖也称之为耦合.而耦合越多,之后的维护工作就越困难.那么如果改善系统模块调用关系.减少模块之间的耦合呢?我们接下来就介绍一种解决方案----消息中间件. ...
- Unity 游戏框架搭建 (十五) 优雅的QChain (零)
加班加了三个月终于喘了口气,博客很久没有更新了,这段期间框架加了很多Feature,大部分不太稳定,这些Feature中实现起来比较简单而且用的比较稳定的就是链式编程支持了. 什么是链式编程? 我想大 ...
- Python基础—07-函数使用(01)
#函数使用 零碎知识 灵活的if-else a = 3 if False else 5 # 等价于 if False: a = 3 else: a = 5 灵活的and/or # 当前面为真,才会进行 ...
- java8新特性学习2
六.Stream API Java8中有两大最为重要的改变.第一个是 Lambda 表达式:另外一个则是 Stream API(java.util.stream.*).Stream 是 Java8 中 ...
- iOS之网络请求及各类错误代码含义总结(包含AFN错误码大全)
转自http://blog.csdn.net/wangyanchang21/article/details/50932191 在很多时候都会遇到错误, 还会带有一些 Error Code , 比如在各 ...
- SQL Server中的三种Join方式
1.测试数据准备 参考:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek 这篇博客中的实验数据准备.这两篇博客使用了相同的实验数据. 2.SQ ...
- 规避Javascript多人开发函数和变量重名问题
函数和变量重名始终是一个令人头痛的问题,先讲变量吧,相信了解JS的朋友都知道,在JS中 是没有块级作用域的只有函数作用域,也就是说那些以大括号为界定符的代码块是管不住其中定义 的变量的作用域的,举例: ...
- ABAP术语-ABAP Workbench
ABAP Workbench 原文:http://www.cnblogs.com/qiangsheng/archive/2007/12/10/989037.html Integrated graphi ...