v-bind绑定属性样式
一、class的四种绑定方式
1、布尔值的绑定方式
<div id="demo">
<span v-bind:class="{'class-a':isA ,'class-b':isB}"></span>
</div>
var vm = new Vue({
el:"#demo",
data:{
isA: true,
isB: true
}
})

2、变量的绑定方式
<div id="demo">
<span :class=[classA,classB]></span>
</div>
var vm = new Vue({
el:"#demo",
data:{
classA:"class-a",
classB:"class-b"
}
})

3、字符串绑定方式
<div id="demo">
<span :class="classA"></span>
</div>
var vm = new Vue({
el:"#demo",
data:{
classA:"string"
}
})

4、三目运算
<div id="demo">
<p :class="isclass?classC:classD"></p>
</div>
var vm = new Vue({
el:"#demo",
data:{
classC:"C",
classD:"D",
isclass:true
}
})

5、综合的写法
<div id="demo">
<span :class="[one,{'classA':classa,'classB':classb}]"></span>
</div>
var vm = new Vue({
el:"#demo",
data:{
one:"string",
classa:true,
classb:false
}
})

<p :style="{fontSize:font,color:red}">绑定style</p>
背景图片写法 链接有()会和css的url()冲突,需要再用一层引号将其包住
:style="{background:'url(\''+item.img+'\') no-repeat center/cover'}" 或者
<p :style="styleObject">用对象绑定style</p>
data:{
font:"24px",
red:"red",
styleObject:{
fontSize:"30px",
color:"pink"
}
}
在methods和computed中写样式用return返回
在methods方法中使用
:style="_sublineStyle(item)" _sublineStyle (item) {
return `-webkit-transform:rotate(${item}deg) translateX(-50%);transform:rotate(${item}deg) translateX(-50%);`
}, 在computed计算属性中使用
:style="[diameter]" diameter () {
return {
width: this.r * 2 + 'px',
height: this.r * 2 + 'px'
}
}
v-bind绑定属性样式的更多相关文章
- v-bind绑定属性样式——class的三种绑定方式
1.布尔值的绑定方式 <div id="demo"> <span v-bind:class="{‘class-a‘:isA ,‘class-b‘:isB ...
- vue v-bind绑定属性和样式
这期跟大家分享的,是v-bind指令.它可以往元素的属性中绑定数据,也可以动态地根据数据为元素绑定不同的样式. 绑定属性 最简单的例子,我们有一张图片,需要定义图片的src.我们可以直接在元素的属性里 ...
- x:bind不支持样式文件 或 此Xaml文件必须又代码隐藏类才能使用{x:Bind} 解决办法
这两天学习UWP开发,发现一个很有趣的问题,就是我题目中的描述的. 我习惯了在ResourceDictionary中写样式文件,但是发现用x:Bind时会有问题 如果是写在Style里,则提示 “x: ...
- 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合
[源码下载] 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合 作 ...
- 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧
[源码下载] 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧 作者:webabcd 介绍背水一战 Wind ...
- 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧
背水一战 Windows 10 之 绑定 x:Bind 绑定 x:Bind 绑定之 x:Phase 使用绑定过程中的一些技巧 示例1.演示 x:Bind 绑定的相关知识点Bind/BindDemo.x ...
- 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合
背水一战 Windows 10 之 绑定 通过 Binding 绑定对象 通过 x:Bind 绑定对象 通过 Binding 绑定集合 通过 x:Bind 绑定集合 示例1.演示如何通过 Bindin ...
- js原生设计模式——8单例模式之简约版属性样式方法库
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- Vue 目录结构 绑定数据 绑定属性 循环渲染数据
一.目录结构分析 node_modules 项目所需要的各种依赖 src 开发用的资源 assets 静态资源文件 App.vue 根组件 main.js 配置路由时会用 .babelrc 配置文件 ...
随机推荐
- how to add borders for a google map marker 谷歌地图 自己定义图钉
If you are not satisfied with default Google map Marker (Default google marker can only be a icon, i ...
- beginAppearanceTransition
- (void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated __OSX_AVAILABLE_STARTING ...
- SQLSERVER数据导入到MYSQL
SQLSERVER数据导入到MYSQL http://hi.baidu.com/luck001221/item/cb4462299f9ea79ab73263d2?qq-pf-to=pcqq.group ...
- spring的bean容器加载
1.在单独使用的时候可以通过ClassPathXmlApplicationContext(“配置文件.xml”);来启动容器. 2.在MVC下是通过启动servlet容器,初始化DispatcherS ...
- HTML <input> <button> <submit>
定义和用法 value 属性规定与按钮关联的初始值.请始终为按钮规定 type 属性,如果不填默认值是 "submit".submit其实就是一个特殊的button. <bu ...
- [参考资料] 80个Python经典资料(教程+源码+工具)汇总
AD : 2018重磅地面课程<机器读心术之语音识别前沿实战特训营>,迈向人工智能新高度 [专题推荐]Python系列英文原版电子书 http://down.51cto.com/zt/10 ...
- testng入门教程4用TestNG执行case
使用TestNG类执行测试用例.这个类的主入口点在TestNG的框架运行测试.用户可以创建自己的TestNG的对象,并调用它以许多不同的方式: 在现有的testng.xml 合成testng.xml, ...
- Vim/Vi的使用
Vim 是vi的加强 Gvim图形化的vim Vim/Vi简介 Vim/Vi是一个功能强大的全屏幕文本编辑器,是Linux/Unix上最常用的文本编辑器,他们 的作用是建立,编辑,显示文本文件 Vi ...
- Chapter 7 Integrity(完整性), Views(视图), Security(安全性), and Catalogs(目录)
from Database Design to Physical Form CREATE TABLE integrity constraints (完整性约束) CREATE VIEW Securit ...
- BinarySearch
今天看代码,看到这么一段,开始没有看明白,记录下来备忘 foreach (FinancialReport r3 in addAorList) { i ...