一、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'}" 或者
  :style="'background:url('+arror+') 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绑定属性样式的更多相关文章

  1. v-bind绑定属性样式——class的三种绑定方式

    1.布尔值的绑定方式 <div id="demo"> <span v-bind:class="{‘class-a‘:isA ,‘class-b‘:isB ...

  2. vue v-bind绑定属性和样式

    这期跟大家分享的,是v-bind指令.它可以往元素的属性中绑定数据,也可以动态地根据数据为元素绑定不同的样式. 绑定属性 最简单的例子,我们有一张图片,需要定义图片的src.我们可以直接在元素的属性里 ...

  3. x:bind不支持样式文件 或 此Xaml文件必须又代码隐藏类才能使用{x:Bind} 解决办法

    这两天学习UWP开发,发现一个很有趣的问题,就是我题目中的描述的. 我习惯了在ResourceDictionary中写样式文件,但是发现用x:Bind时会有问题 如果是写在Style里,则提示 “x: ...

  4. 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合

    [源码下载] 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合 作 ...

  5. 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧

    [源码下载] 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧 作者:webabcd 介绍背水一战 Wind ...

  6. 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧

    背水一战 Windows 10 之 绑定 x:Bind 绑定 x:Bind 绑定之 x:Phase 使用绑定过程中的一些技巧 示例1.演示 x:Bind 绑定的相关知识点Bind/BindDemo.x ...

  7. 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合

    背水一战 Windows 10 之 绑定 通过 Binding 绑定对象 通过 x:Bind 绑定对象 通过 Binding 绑定集合 通过 x:Bind 绑定集合 示例1.演示如何通过 Bindin ...

  8. js原生设计模式——8单例模式之简约版属性样式方法库

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

  9. Vue 目录结构 绑定数据 绑定属性 循环渲染数据

    一.目录结构分析 node_modules 项目所需要的各种依赖 src 开发用的资源 assets 静态资源文件 App.vue 根组件 main.js 配置路由时会用 .babelrc 配置文件 ...

随机推荐

  1. 64位win10+cuda8.0+vs2013+cuDNN V5下Caffe的编译安装教程并配置matlab2014a 接口

    一.需要安装的软件 1)vs2013,我是在http://www.52pojie.cn/thread-492326-1-1.html这个网址安装的.我之前用的是vs2012,按照网上的配置教程会爆各种 ...

  2. 协作工具 discord 和 slack

    discord: https://discordapp.com/ slack: www.slack.com

  3. PAT 1049 Counting Ones[dp][难]

    1049 Counting Ones (30)(30 分) The task is simple: given any positive integer N, you are supposed to ...

  4. spring-data-mongodb关于id的坑

    有如下Mongo记录: 在Java中对应2个类来表示此结构: public class SG_IMAGERELATION { @Id private String id; private int gi ...

  5. Http请求中Content-Type和Accept讲解以及在Spring MVC中的应用

    在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值,以及在 ...

  6. Twitter OA prepare: Anagram is A Palindrome

    Algorithm: Count the number of occurrence of each character. Only one character with odd occurrence ...

  7. C++声明和定义

    目录 1 参考 2 概念 2.1 声明 2.2 定义 3 对比 3.1 声明但不是定义的情况 3.2 声明且是定义的情况 3.3 特殊情况 1. 参考 1. <C++程序设计语言>4.9 ...

  8. 关于 WebBrowser调用百度地图API 鼠标滚轮缩放地图级别失灵的解决办法

    在桌面程序下 百度地图API的鼠标缩放地图功能可能会失灵无效! 这个原因不是API的问题 小弟试了下在WEB上面是没有问题的 于是考虑可能是WebBrowser的获取焦点问题,于是在主窗体 添加了一个 ...

  9. cf463d

    这题说的是给了k个串算出这k个串的最长公共子序列,这k个串每个串都是由1--n的数字组成的. 将第一串的数字按照顺序重新编号为123...n 然后后面的串按照这个编号重新标号,就转化为下面每个串大最长 ...

  10. Intro to Python for Data Science Learning 6 - NumPy

    NumPy From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4-numpy?ex=1 ...