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名需要 ...
随机推荐
- Zookeep启动异常:Error contacting service. It is probably not running.
异常提示: [root@hadoop bin]# ./zkServer.sh status JMX enabled by default Using config: /usr/local/zk/bin ...
- 【JeeSite】角色和权限的修改
@RequiresPermissions("sys:role:edit") @RequestMapping(value = "save") public Str ...
- 【luogu P1993 小K的农场】 题解
题目链接:https://www.luogu.org/problemnew/show/P1993 1.差分约束: 对于a - b <= c 有一条 b-->a 权值为c 对于a - b & ...
- java GZIP 压缩数据
package com.cjonline.foundation.cpe.action; import java.io.ByteArrayInputStream; import java.io.Byte ...
- eclipse 安装/卸载插件
1.通过Help>>Install New Soft 之后弹出对话框,可以通过“Add”按钮添加已经有的插件的(zip等)或者输入安装地址,之后按照要求即可.2.对于安装失败的插件,再次进 ...
- [转]Matlab2012b安装详解
matlab2012b安装文件下载: http://yunpan.cn/cVY5VsSeUXzai (提取码:ec84) 1.双击setup.exe进行安装.安装中选择“不使用Internet安装” ...
- webpack——概念的引入
## 在网页中会引用哪些常见的静态资源?+ JS - .js .jsx .coffee .ts(TypeScript 类 C# 语言)+ CSS - .css .less .sass .scss+ I ...
- 轻量ORM-SqlRepoEx (二)初始化SqlRepoEx
一.SqlRepoEx引用 暂时没放至nuget上,可以直接到https://github.com/AzThinker/SqlRepoEx下载源码,编译引用. (一).静态引用 1.需引用以下dll在 ...
- 使用actionerror做失败登录验证
一. 登录页面中放置如下代码: <h4>员工登录</h4> <div style="color:red"> <s:actionerror/ ...
- spring配置多个视图解析
<!-- 配置视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceVie ...