zoukankan      html  css  js  c++  java
  • 3.绑定属性、绑定html、绑定class、绑定style

    1.绑定属性

    <template>
      <div id="app">
        
        <!-- 绑定属性 -->
        <br>
        <div v-bind:title='title'>鼠标悬浮出现</div>
        <br>
        <img :src="url" alt="仙女">
        
    
      </div>
    </template>
    
    <script>
    export default {
      name: 'app',
      data () {
        return {
          title:'鼠标悬浮出现',
          url:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1569319252742&di=0eaf19ed1e01d10d7f612da9434599a6&imgtype=0&src=http%3A%2F%2Fimg3.duitang.com%2Fuploads%2Fitem%2F201603%2F28%2F20160328121906_ErzAB.thumb.700_0.jpeg'
        }
      }
    }
    </script>
    
    <style>
    
    </style>

    2.绑定html

    <template>
      <div id="app">
        
        <!-- html绑定 -->
        <div v-html="h"></div>
    
      </div>
    </template>
    
    <script>
    export default {
      name: 'app',
      data () {
        return {
          h:'<h2>二级标题</h>'
        }
      }
    }
    </script>
    
    <style>
    
    </style>

     3.绑定class

    <template>
      <div id="app">
        
        <!-- 绑定class -->
        <div :class="{'red':flag,'blue':!flag}">绑定class</div>
        <div :class="{'red':!flag,'blue':flag}">绑定class</div>
    
        <ul>
          <li v-for="(item,index) in list" :key=index :class="{'red':index==1,'blue':index==2}">{{item}}</li>
        </ul>
    
      </div>
    </template>
    
    <script>
    export default {
      name: 'app',
      data () {
        return {
          flag:true,
          list:['第一行','第二行','第三行']
        }
      }
    }
    </script>
    
    <style>
    
    .red{color: red}
    .blue{color:blue}
    
    </style>

    4.绑定style

    <template>
      <div id="app">
        <!-- 绑定style  -->
        <div class="box" :style="{boxWidth+'px'}">这是一个div</div>
    
      </div>
    </template>
    <script>
    export default {
      name: 'app',
      data () {
        return {
          boxWidth:300
        }
      }
    }
    </script>
    <style>
    .box{
      height: 100px;
      width: 100px;
      background-color: aquamarine;
    }
    </style>

  • 相关阅读:
    【Python数据分析】NumPy之数组对象基础
    【Oracle11g】20_函数
    【Word】排版技巧
    cache介绍
    cache verilog实现
    在verilog中使用格雷码
    同步fifo与异步fifo
    AHB总线协议(二)
    Android Handler 消息机制原理解析
    值得推荐的开源C/C++框架和库
  • 原文地址:https://www.cnblogs.com/xuepangzi/p/11578524.html
Copyright © 2011-2022 走看看