Vue学习笔记

Vue学习笔记

一、引入vue.js库

<script type="text/javascript" src="https://cdn.bootcss.com/vue/2.6.0/vue.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue学习</title>
    <script type="text/javascript" src="https://cdn.bootcss.com/vue/2.6.0/vue.js"></script>
</head>
<body>
<div id="app">
    <h2>{{msg}}</h2>
</div>
<script>
    new Vue({
        el : '#app',
        data:{
            msg : "vue基本模板",
        },
        methods:{
        }

    })
</script>
</body>
</html>

在这里插入图片描述

二、网址的跳转、点击事件、div中绑定html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue学习</title>
    <script type="text/javascript" src="https://cdn.bootcss.com/vue/2.6.0/vue.js"></script>
</head>
<body>
<div id="app" class="appstyle">
    <h2>{{msg}}</h2>
    <br>
    <!--两种网址跳转方式-->
    <a v-bind:href="url">百度</a>
    <a :href="url">百度</a>
    <br>
    <!--绑定html模板-->
    <div v-html="template">
    </div>
    <!--每次点击count++-->
    {{count}}
    <button type="button" @click="submit()">add</button>
</div>
<script>
    new Vue({
        el : '#app',
        data:{
            msg : "vue基本模板",
            url : "http://www.baidu.com",
            count : 0,
            template: '<div>hello template</div>'
        },
        methods:{
            submit : function(){
                this.count++
            }
        }

    })
</script>
</body>
</html>

三、条件渲染

根据数值的大小确定是否渲染

<div id="app3"  class="appstyle">
    <h2>{{msg}}</h2>
    <br>
    <div v-if="count > 0">
        判断一:count 大于0 ,count是{{count}}
    </div>
    <div v-else-if="count < -1 && count > -5">
        判断二:count 不大于0 ,count是{{count}}
    </div>
    <div v-else>
        判断三:count 不大于0 ,count是{{count}}
    </div>
</div>
<script>
    var app3 = new Vue({
        el : '#app3',
        data:{
            msg : "条件渲染",
            count : 0,
        },
        methods:{

        }

    })
</script>
<div id="app3"  class="appstyle">
    <div v-for="item in list">
        <div v-if="item.age > 31">
            {{item.age}} 年龄大于31,没有样式
        </div>
        <div v-else
             :style = "stylemsg"
             :class="['active', 'add', 'more', {'stylemsg' : item.age > 20}]">
            {{item.name}}年龄小于等于31,有样式
        </div>
    </div>
</div>
<script>
    var app3 = new Vue({
        el : '#app3',
        data:{
            msg : "条件渲染",
            count : 0,
            stylemsg:{
                color: "red",
                textShadow:'0 0 5px green'
            },
            list : [{
                name:"zhansan",
                age:30
            },
                {
                    name:"lisi",
                    age:35
                }]
        },
        methods:{

        }

    })
</script>

在这里插入图片描述

四、变量属性监听

<div id="app2"  class="appstyle">
    <h2>{{msg}}</h2>
    <br>
    <p>
        {{msg1}}
    </p>
</div>
<script>
    var app2 = new Vue({
        el : '#app2',
        data:{
            msg : "计算属性与监听器",
            another: "another "
        },
        //监听器:异步场景,一个变量
        watch:{
            msg:function (newval, oldval) {
                console.log("msg新的变量" + newval)
                console.log("msg旧的变量" + oldval)
            }
        },
        //计算属性:数据联动,多个变量
        computed:{
        },
        methods:{

        }

    })
</script>

在这里插入图片描述

<div id="app2"  class="appstyle">
    <!--<h2>{{msg}}</h2>-->
    <!--<br>-->
    <p>
        {{msg1}}
    </p>
</div>
<script>
    var app2 = new Vue({
        el : '#app2',
        data:{
            msg : "计算属性与监听器",
            another: "another "
        },
        //监听器:异步场景,一个变量
        watch:{
        },
        //计算属性:数据联动,多个变量
        computed:{
            msg1: function () {
                return 'computed ' + this.msg +" " + this.another
            }
        },
        methods:{

        }

    })
</script>

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不染心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值