VUE基础使用

VUE基础使用

<html>
    <head>
        <title>
            VUE基础
        </title>
        <style>
            .active{
                border: 1px solid red;           
            }
        </style>
    </head>

<body>
    <div id="app">
        {{ message }}
        <h2>
            {{ school.name }}
            {{school.mobile }}
        </h2>
        <ul>
            <li>
                {{ campus[0] }}
            </li>
            <li>
                {{ campus[1] }}
            </li>
        </ul>
        <h2 v-text="message+'!!!!'">
        </h2>
        <p v-html="content"></p>
        <!-- v-on:click @click 点击事件 -->
        <input type="button" value="v-on指令" v-on:click="doIT">
        <input type="button" value="v-on简写" @click="doIT">
        <input type="button" value="双击事件" @dblclick="doIT">
        <div class="input-num">
            <button @click="sub">-</button>
            <span>{{ num }}</span>
            <button @click="add">+</button>
        </div>

        <input type="button" value="切换显示状态" @click="changeIsShow">
        <img v-show="isShow" src="./img/123.png" alt="">
        <img v-show="num>=7" src="./img/123.png" alt="">
        
        <p v-if="isShow">合肥</p>
        <!-- v-show和v-if的区别,v-show只是修改display,v-if直接把html代码给去除了 -->
        
        <!-- v-bind 设置元素属性 -->
        <img v-bind:src="imgSrc" alt="">
        <img :src="imgSrc" alt="" :title="isTitle"
        :class="isActive?'active':''" @click="toggleActive">
        <br>
        
        <!-- 简写 class可以用对象的方式 -->
        <img :src="imgSrc" alt="" :title="isTitle"
        :class="{active: isActive}" @click="toggleActive">
        
        <!--轮播图-->
        <img :src="imgArr[index]" alt="" />
        <a href="javascript:void(0)" class="left" v-show="index!=0" @click="prev">
            上一张
        </a>
        <a href="javascript:void(0)" class="right" v-show="index<imgArr.length-1" @click="next">
            下一张
        </a>

        <!-- v-for -->
        <ul>
            <li v-for="(item,index) in arr">
                {{ item }}{{ index }}
            </li>
        </ul>
        <h2 v-for="item in vegetables" v-bind:title="item.name">
            {{ item.name }}
        </h2>
        <input type=" " value="添加数据" @click="arr_add">
        <input type="button" value="删除数据" @click="remove_arr"> 
        
        <!-- v-on传递自定义参数,事件修饰符 -->
        <!-- 事件修饰符地址: https://cn.vuejs.org/v2/api/#v-on -->
        <input type="button" value="点击" @click="on_doit(666)">
        <input type="text" @keyup.enter="sayHi">  <!--回车触发-->
        <br>

        <!-- v-model 双向数据绑定 -->
        <input type="text" v-model="model_text" @keyup.enter="getM">
        <h2>{{ model_text }}</h2>
    
    
    </div>
</body>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    var app = new Vue({
        el: "#app",
        data:{
            message:"Hello Vue",
            school:{
                name: "三中",
                mobile: "123456"
            },
            campus: ["北京", "合肥"],
            content: "<a href='www.baidu.com'>严旭</a>",
            num: 1,
            isShow: false,
            imgSrc: "https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeel5.png",
            isTitle: "测试地址说明",
            isActive: false,
            imgArr: ["./img/DSC_1595.JPG",
            "./img/DSC_1597.JPG",
            "./img/DSC_1598.JPG",
            "./img/DSC_1602.JPG",
            "./img/DSC_1604.JPG"
        ],
            index: 0,
            arr: [1,2,3,4,5,6],
            vegetables:[
                {name: "西红柿炒鸡蛋"},
                {name: "可乐鸡翅"}
            ],
            model_text: "双向绑定数据测试"


        },
        methods:{
            doIT:function(){
                alert("123")
            },
            add:function(){
                // console.log("add")
                if(this.num<10){
                    this.num++;
                }else{
                    alert("别点了,最大值10")
                }
    
            },
            sub:function(){
                // console.log("sub")
                if(this.num>0){
                    this.num--;
                }else{
                    alert("已经到最小值了")
                }
            },
            changeIsShow:function(){
                this.isShow=!this.isShow
            },
            toggleActive:function(){
                this.isActive=!this.isActive
            },
            prev:function(){
                this.index--;
        },
            next:function(){
                this.index++;
        },
        arr_add:function(){
            this.vegetables.push({name: "土豆丝"})
        },
        remove_arr:function(){
            this.vegetables.shift()
        },
        on_doit:function(p1){
            console.log(p1)
        },
        sayHi:function(){
            alert('xxxxx')
        },
        getM:function(){
            alert(this.model_text)
        },
    },
});
</script>
  </html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值