登录
首页 >  数据库 >  MySQL

vue实现的双向数据绑定操作示例

来源:SegmentFault

时间:2023-02-16 15:23:33 499浏览 收藏

本篇文章向大家介绍《vue实现的双向数据绑定操作示例》,主要包括MySQL、nginx、github、spring、javascript,具有一定的参考价值,需要的朋友可以参考一下。


 
 <meta charset="UTF-8"><title>经典的双向数据绑定</title><script src="https://cdn.bootcss.com/vue/2.0.1/vue.min.js"></script><div id="container">
  <button>修改msg</button>
 方向1:将定义好的数据绑定到试图 
实现方式:双花括号 
常见指令:v-for v-if v-show …… -->
<!-- 方向2:将视图中用户操作的结果 绑定到指定的数据  (多数指表单控件 input/textarea/select)
  实现方式: v-model
-->
    <p>{{msg}}</p>
    &lt;input type=&quot;text&quot; v-model=&quot;userAddress&quot;&gt;<p>{{"用户修改的数据:"+userAddress}}</p>
    <hr><h2>v-model.number</h2>
    &lt;input type=&quot;text&quot; v-model.number=&quot;n&quot;&gt;<br>&lt;input type=&quot;text&quot; v-model.number=&quot;m&quot;&gt;<br><button>求和</button>
    <span>{{num}}</span>
    <hr><h2>v-model.trim</h2>
    <h5>没有过滤首尾空格时:</h5>
    &lt;input type=&quot;text&quot; v-model=&quot;myInput&quot;&gt;<span>{{myInput.length}}</span>
    <h5>过滤首尾空格时:</h5>
    &lt;input type=&quot;text&quot; v-model.trim=&quot;myInput&quot;&gt;<span>{{myInput.length}}</span>
    <h2>v-moddel.lazy</h2>
    <h5>input失去焦点时才会输出myMsg</h5>
    &lt;input type=&quot;text&quot; v-model.lazy=&quot;myMsg&quot;&gt;<span>{{myMsg}}</span>
  </div>
欢迎加入全栈开发交流划水交流圈:582735936
面向划水1-3年前端人员
帮助突破划水瓶颈,提升思维能力
  <script>
    new Vue({
      el:"#container",
      data:{
        msg:"Hello VueJs",
        userAddress:"",
        n:0,
        m:0,
        num:0,
        myInput:0,
        myMsg:""
      },
      methods:{
        modifyMsg:function(){
          this.msg = "Hello Model"
        },
        getNum:function(){
          this.num = this.n+this.m;
        }
      }
    })
  </script>

使用在线HTML/CSS/JavaScript代码运行工具http://tools.jb51.net/code/HtmlJsRun测试,可得到如下运行效果

今天带大家了解了MySQL、nginx、github、spring、javascript的相关知识,希望对你有所帮助;关于数据库的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>