美文网首页
v-bind绑定属性

v-bind绑定属性

作者: greenPLUS | 来源:发表于2018-09-13 15:00 被阅读0次

    //v-bind是用来绑定属性的 v-bind:src(任何属性)=“”

    <body>
    <div id="itany">
        <img v-bind:src="url" alt="" v-on:click="alt">
    </div>
    <script src="dist/vue.js"></script>
    <script>
        new Vue({
            el:'#itany',
            data:{
                url:'img/1.jpg',//这是上边的内容
                urk:'true'
            },
            methods:{
                alt:function(){
                    if (this.urk){
                        this.url='img/2.jpg',
                        this.urk=false
                    }else {
                        this.url='img/1.jpg',
                        this.urk=true
                    }
                }
            }
        })
    </script>
    </body>
    
    //这最后出来的效果是点击来回切换图片
    

    相关文章

      网友评论

          本文标题:v-bind绑定属性

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