码迷,mamicode.com
首页 > 其他好文 > 详细

06.VUE学习之非常实用的计算属性computed实例

时间:2019-01-05 10:46:18      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:UNC   9.png   vue.js   rip   img   on()   ble   app   inpu   

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>vue</title>
    <link rel="stylesheet" href="">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!-- <script type="text/javascript" src="../js/vue.js"></script> -->

</head>
<body>
    <div id="vue">
        <input type="text" v-model="n1">+
        <input type="text" v-model="n2">=
        <input type="text" v-model="sum">
    </div>
</body>
<script type="text/javascript">
    var app=new Vue({
        el:‘#vue‘,
        computed:{
//          写法一:
            sum:function(){
                //*1 是把字符串转为数字型 用this会从data里找变量
                return this.n1*1+this.n2*1;
            }
//          写法二:
//          sum(){
//              return this.n1*1+this.n2*1
//          }
        },
        data:{
          n1:0,
          n2:0,
        }
    });
</script>
</html>

效果:
技术分享图片

06.VUE学习之非常实用的计算属性computed实例

标签:UNC   9.png   vue.js   rip   img   on()   ble   app   inpu   

原文地址:https://www.cnblogs.com/haima/p/10223512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!