Vue2.0实例双向数据绑定

结果展示:






<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>双向数据绑定</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<style>
    [v-cloak]{
        display:none;
    }
    *{
        margin:0;
        padding:0;
    }
    body{
        font-family:Microsoft YaHei;
        text-align: center;
    }
    li{
        list-style:none;
    }
    #main{
        height:300px;
        position:relative;
        padding-top:150px;
    }
    .tooltip{
        background-color:#5c9bb7;
        border-radius:3px;
        width: 280px;
        padding:10px;
        position: absolute;
        left:50%;
        margin-left:-150px;
        top:80px;
    }
    .tooltip:after{
        content: '';
        position: absolute;
        border:6px solid #5190ac;
        border-color: #5190ac transparent transparent;
        width:0;
        height:0;
        bottom: -12px;
        left:50%;
        margin-left: -6px;
    }
    .tooltip input{
        border:none;
        width:100%;
        line-height: 34px;
        border-radius: 3px;
        box-shadow: 0 2px 6px #bbb inset;
        text-align: center;
        font-size:16px;
        font-family: inherit;
        color: #8d9385;
        font-weight: bold;
        outline:none;
    }
    p{
        font-size: 22px;
        font-weight: bold;
        color:#6d8088;
        height:30px;
        cursor: pointer;
    }
    p:before{
        content:'✎';
        display: inline-block;
        margin-right:5px;
        font-weight:normal;
        vertical-align: text-bottom;
    }
</style>
<body>
    <div id="main" v-cloak @click="hideTooltip">
        <div class="tooltip" v-if="show_tooltip" @click.stop><!--修饰符.stop应该放在需要阻止冒泡的位置上。-->
            <input type="text" v-model="text_content"/>
        </div>
        <p @click.stop="toggleTooltip">{{text_content}}</p>
    </div>
</body>
<script type="text/javascript">
    var demo=new Vue({
        el:'#main',
        data:{
            show_tooltip:false,
            text_content:'Edit me.'
        },
        methods:{
            hideTooltip:function(){
                this.show_tooltip=false;
            },
            toggleTooltip:function(){
                this.show_tooltip=!this.show_tooltip;
            }
        }
    })
</script>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值