4.29_Vue学习入门第二篇

1:图片切换案例

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>vue入门</title>
    <style>
        .active{
            border: 1px solid red;
        }
    </style>
</head>
<!--/*vue的作用范围是在而来*/-->
<body>
<div id="app">
    <!--    插值表达式-->
    <a href="javascript:void(0)" v-show="index!=0" @click="prev" ><</a>
   <img v-bind:src="inmage[index]" style="    width: 1000px;
    height: 500px;">
    <a href="javascript:void(0)" v-show="index<inmage.length-1" @click="next">
        >
    </a>
    <br>

<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    var app=new Vue({
        el:'#app',
        data:{
          inmage:["pic/timg.png","pic/timg1.png","pic/timg2.png","pic/timg4.png","pic/timg5.png"],
            index:0
        }
        ,
        methods:{
           prev:function () {
               this.index--;
           },
            next:function () {
              this.index++;
            }
        }

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

2:v-for
在这里插入图片描述
代码:

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>vue入门</title>
</head>
<!--/*vue的作用范围是在而来*/-->
<body>
<div id="app">
    <input type="button" @click="add" value="添加"><input type="button" @click="amove" value="删除">
    <ul v-for="(it,index) in inm" >
        <li>{{index+1}}黑马程序员学校:{{it}}</li>
    </ul>
    <div v-for="(ie,index) in vage" :title="ie.name">
        <h2>
      {{ie.name}}
        </h2>
    </div>



<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    var app=new Vue({
        el:'#app',
        data:{
         inm:["北京","上海","广州","深圳"],
            vage:[{name:"西兰花炒蛋"}, {name:"蛋炒西兰花"}]
        }
        ,
        methods:{
          add:function () {
              // 添加
               this.vage.push({name:"水煮鱼"});
           },
            amove:function () {
              // 删除
              this.vage.shift();
            }
        }

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

运行结果:
在这里插入图片描述
在这里插入图片描述
3:v-on补充
在这里插入图片描述

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>vue入门</title>
</head>
<!--/*vue的作用范围是在而来*/-->
<body>
<div id="app">
<!--单击弹出"666""女孩"-->
    <input type="button" @click="add(666,'女孩')" value="单击">
<!--    按回车的时候弹出"你好啊"-->
<input type="text" @keyup.enter="amove">

<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    var app=new Vue({
        el:'#app',
        data:{
         inm:["北京","上海","广州","深圳"],
            vage:[{name:"西兰花炒蛋"}, {name:"蛋炒西兰花"}]
        }
        ,
        methods:{
          add:function (p1,p2) {
            alert(p1);
            alert(p2);

           },
            amove:function () {
              alert("你好啊");
            }
        }

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

在这里插入图片描述
4:v-model

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>vue入门</title>
</head>
<!--/*vue的作用范围是在而来*/-->
<body>
<div id="app">
    <input type="button" value="按钮" @click="amove">
    <input type="text" v-model="inm" @keyup.enter="add">
    <h2>
        {{inm}}
    </h2>
</div>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    var app=new Vue({
        el:'#app',
        data:{
         inm:"黑马"

        }
        ,
        methods:{
          add:function () {
           alert(this.inm);
           },
            amove:function () {
             this.inm="女孩",
                 alert(this.inm)
            }
        }

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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值