vue学习08 v-bind指令

v-bind指令的作用是为元素绑定属性

完整写法是v-bind:属性名,可简写为:属性名

练习代码为:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-bind</title>
</head>
<style>
    .active{
        border:1px solid red;
    }
</style>
<body>
    <!-- v-bind 为元素绑定属性 :是简写  -->
    <div id="app">
        <img v-bind:src="imgSrc" alt=""><br>
        <img :src="imgSrc" alt="" :title="imgTitle+'!!!'"
        :class="isActive? 'active':''" @click="toggleActive">
        <br>
        <img :src="imgSrc" alt="" :title="imgTitle+'!!!'"
        :class="{active:isActive}" @click="toggleActive">
    </div>

    <script src="js/vue.js"></script>
    <script>
        var app = new Vue({
            el:"#app",
            data: {
                imgSrc: "images/123.jpg",
                imgTitle:"侠客小飞喜欢学vue!",
                isActive: false
            },
            methods: {
                toggleActive: function() {
                    this.isActive = !this.isActive;
                }
            }
        })
    </script>
</body>
</html>

运行效果为:

image-20200925084455119

版权声明:本文为ma1998原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/ma1998/p/13728093.html