美文网首页
vue 添加样式分几种方法

vue 添加样式分几种方法

作者: 上海_前端_求内推 | 来源:发表于2021-07-15 09:10 被阅读0次

1,

<body>
<div id="app">
  <div v-bind:class="{ active: isActive }"></div>
</div>
 
<script>
new Vue({
  el: '#app',
  data: {
    isActive: true
  }
})
</script>

2,

<div id="app">
  <div class="static"
     v-bind:class="{ active: isActive, 'text-danger': hasError }">
  </div>
</div>
 
<script>
new Vue({
  el: '#app',
  data: {
    isActive: true,
    hasError: true
  }
})

3,

<style>
.active {
    width: 100px;
    height: 100px;
    background: green;
}
.text-danger {
    background: red;
}
</style>
</head>
<body>
<div id="app">
  <div v-bind:class="classObject"></div>
</div>
 
<script>
new Vue({
  el: '#app',
  data: {
    classObject: {
      active: true,
      'text-danger': true
    }
  }
})

4,

<style>
.active {
    width: 100px;
    height: 100px;
    background: green;
}
.text-danger {
    background: red;
}
</style>
</head>
<body>
<div id="app">
    <div v-bind:class="[activeClass, errorClass]"></div>
</div>
 
<script>
new Vue({
  el: '#app',
  data: {
    activeClass: 'active',
    errorClass: 'text-danger'
  }
})
</script>

5,

<style>
.text-danger {
    width: 100px;
    height: 100px;
    background: red;
}
.active {
    width: 100px;
    height: 100px;
    background: green;
}
</style>
</head>
<body>
<div id="app">
    <div v-bind:class="[errorClass ,isActive ? activeClass : '']"></div>
</div>
 
<script>
new Vue({
  el: '#app',
  data: {
    isActive: true,
    activeClass: 'active',
    errorClass: 'text-danger'
  }
})
</script>

6,

<div id="app">
    <div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">菜鸟教程</div>
</div>
 
<script>
new Vue({
  el: '#app',
  data: {
    activeColor: 'green',
    fontSize: 30
  }
})

相关文章

  • vue 添加样式分几种方法

    1, 2, 3, 4, 5, 6,

  • Vue 插件开发指南

    Vue插件的编写方法一般有下面几种: 添加全局方法或者属性,如: vue-custom-element 添加全局资...

  • vue解决vant组件样式失效问题

    vue项目中引入vant组件,若发现vant组件样式失效,通常有以下几种解决方法: 方法一:引入全局样式  在引入...

  • vue判断各种状态添加样式

    vue项目中常常会根据某种状态添加样式一些样式,比如每个网站顶部都会根据进入某个页面添加某些样式。 解决方法:可以...

  • Vue 插件

    Vue 插件 插件通常会为 Vue 添加全局功能。插件的范围没有限制——一般有下面几种:添加全局方法或者属性,如:...

  • 24. 插件

    插件通常为vue添加全局功能,一般有以下几种: 添加全局方法或者属性 添加全局资源——指令,过滤器,过渡等等 通过...

  • IOS常用控件学习之UITableView

    添加控件 添加TableView 添加原型单元格image.png 选择样式和ID,系统提供了几种基础样式,我们也...

  • vue绑定class和style

    1.绑定class 方法一:通过在vue实例的data中添加类名来绑定样式。具体流程如下 a.定义样式的class...

  • Vue 插件及Vue.use源码分析

    插件 插件通常用来为 Vue 添加全局功能。插件的功能范围没有严格的限制——一般有下面几种: 添加全局方法或者属性...

  • vue 插件开发--install

    插件通常用来为 Vue 添加全局功能。插件的功能范围没有严格的限制——一般有下面几种: 添加全局方法或者 prop...

网友评论

      本文标题:vue 添加样式分几种方法

      本文链接:https://www.haomeiwen.com/subject/xxdppltx.html