vue入门3

<!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>Document</title>
    <style>
        .red{
            color: red;
        }
        .green{
            color: green;
        }
    </style>
    <script src="./vue.js"></script>
    <script>
        window.onload = function(){
            //三目三元运算
            var money = 100;
            var result = (money>200)?'还有点钱':'需要充值'
            alert(result)
            //创建一个vue对象
            var vm = new Vue({
                el:'.box',
                data:{
                    counter:0,
                    newCounter:0,
                    message:'abcdef',
                    isRed:false
                },
                methods:{
                    fnAdd:function(){
                        // this -->vue对象,解决了跨作用域问题
                        this.counter +=1;
                    }
                }
            })
        }
    
    </script>
</head>
<body>
    <div class="box">
        <!-- v-on: 可以简写成@ -->
        <button v-on:click="fnAdd">累加器:{{counter}}</button>
        <button @click = "newCounter+=1">累加表达式:{{newCounter}}</button>
        <!-- 链式表达式 -->
        <p>逆序:{{message.split('').reverse().join('')}}</p>
        <!-- 这里的v-bind:被简写成了: -->
        <!-- 三目三元运算 为了做对比,我在上面写了一个js版本的三目运算三元运算 -->
        <p :class="isRed?'red':'green'">三目运算</p>

    </div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/owc1874/article/details/80784960