vue.js 学习

 循环 v-for

可以遍历json数组,也可以遍历json对象的所有属性

<template v-for="(akey,index) in dev.pidList">

v-for  可以直拿数组里的元素 dev in devList,也可以拿下标 (dev, index) in devList

下标从0开始,例如:

rooms: [ {name:"111"}, {name:"222"}, {name:"333"}, {name:"444"}, {name:"555"}],
<template v-for="(room, idx) in rooms ">
    {{  idx + "->" + room.name}}
    <br/>
</template>

输出:

0->111
1->222
2->333
3->444
4->555

点击响应

<button  v-on:click="update_device" >刷新</button>

或者:

<button @click="update_device" >刷新</button>

@click可以放在任何div里。

点击响应函数可以加参数,例如:

    <template v-for="(room, idx) in rooms ">
        <p @click="clickRoom(room)">
        {{  idx + "->" + room.name}}
        </p>
    </template>

    new Vue({
        el: '#app',
        data () {
            return {
                rooms: [ {name:"111"}, {name:"222"}, {name:"333"}, {name:"444"}, {name:"555"}]               
            }
        },
        mounted () {

        },
        methods: {
            clickRoom(room) {
                console.log("you click room:" + room.name)
            }
        }
    })

判断

在 html 中动态控制显示

可以理解为只有 v-if 里的条件成立的时候,该标签 img 才会存在。

    <template v-for="(room, idx) in rooms ">
        <p @click="clickRoom(room)">
        <img v-if="idx == 0" src="static/picture/cat-icon1.png">
        <img v-if="idx == 1" src="static/picture/cat-icon2.png">
        <img v-if="idx == 2" src="static/picture/cat-icon3.png">
        <img v-if="idx == 3" src="static/picture/cat-icon4.png">
        <img v-if="idx == 4" src="static/picture/funfact1.png">
            {{  idx + "->" + room.name}}
        </p>
    </template>

 

其它基础

1 判断字符串相等

<template v-if="dev.category === 'switch'">

2 判断json数组长度

    <template v-if="dev.pidList !== undefined && dev.pidList.length > 1 ">
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Zonson9999

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

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

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

打赏作者

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

抵扣说明:

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

余额充值