Vue 数组 字典 template v-for 的使用

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="utf-8">
 5     <title></title>
 6     <link rel="stylesheet" type="text/css" href="vue.css">
 7     <script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
 8 </head>
 9 <body>
10     <div id="vue-app">
11         <h1> v-for 循环</h1>
12         <!--数组下标-->
13         {{    characters[0] }}
14         {{    characters[1] }}
15         {{    characters[2] }}
16         <!--数组遍历-->
17         <ul>
18                 <li v-for="character in characters">
19                     {{character}}
20                 </li>
21         </ul>
22 <hr>
23     <ul>
24         <li v-for="user in userMsg" style="list-style: none;">
25             {{ user }} - {{ user.name }} - {{ user.age }}
26         </li>
27     </ul>
28     <hr>
29
30     <ul><!-- index 默认其实位置是:0 -->
31         <li v-for="(user,index) in userMsg" style="list-style: none;">
32             {{ index }} - {{ user.name }} - {{ user.age }}
33         </li>
34     </ul>
35     <h3><使用 div+v-for/h3>
36         <div v-for="(user,index) in userMsg" >
37             <h3>{{ index+1 }} . {{ user.name }}</h3>
38             <p>&nbsp;Age: {{ user.age }}</p>
39         </div>
40     <hr>
41     <h3>使用template+v-for</h3>
42     <template v-for="(user,index) in userMsg">
43         <h3>{{ index+1 }}.{{ user.name }}</h3>
44         <p>&nbsp;Age:{{ user.age }}</p>
45     </template>
46     以上两种情况 有什么不同?
47      查看html便知
48
49      <h3>使用template+v-for 再加 内 循环 v-for</h3>
50     <template v-for="(user,index) in userMsg">
51             <div v-for="(value,key) in user">
52                 {{ key }}-{{ value }}
53     </template>
54     </div>
55
56     <script src="app.js"></script>
57 </body>
58 </html>

HTML

 1 new Vue({
 2     el:‘#vue-app‘,
 3     data:{
 4         characters:[‘Mario‘,‘Luffy‘,‘Yoshi‘],
 5         userMsg:[
 6             {name:"Henry",age:30},
 7             {name:"Bucky",age:30},
 8             {name:"Emily",age:30},
 9         ],
10     },
11     methods:{
12
13     },
14     computed:{
15
16     }
17 })

Vue.js

原文地址:https://www.cnblogs.com/yanxiatingyu/p/9459419.html

时间: 2024-08-02 08:40:00

Vue 数组 字典 template v-for 的使用的相关文章

vue 数组对象取对象的属性: Cannot read property &#39;xxxx&#39; of undefined

{{ list[0].name }} list[0]没有定义 能正确打印出想要的结果,但就是报错,外面套个v-for就没错了 很费解 与异步有关,解决办法: <template v-if=list[0]> {{ list[0].name }} </template> https://www.v2ex.com/amp/t/402145 vue 数组对象取对象的属性: Cannot read property 'xxxx' of undefined 原文地址:https://www.c

关于vue数组中对象属性变更页面没重新渲染的问题

前段时间做开发的时候用mqtt监听了服务端信息,推送过来的数据要变更数组里面的对象的数据,修改好后但是页面并没有更新,因为javascript机制,vue并不能检测到数组变化,也是查阅知道了$set()函数, 具体用法: arr.$set(index, { name : value }), index: 索引,name: 数组中对象的属性名, value: 要赋给属性的值 this.footerList.$set(i, { siteId : monitorSiteData[j].siteId,

数组字典结合删除排序2 描述器

// //  main.m //  数组字典结合删除排序 // //  Created by 博博 on 16/1/8. //  Copyright (c) 2016年 com.bb. All rights reserved. // #define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]) #import <Foundation

NSNumber(把数字存进数组字典等的问题)

官方文档地址https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/Reference/Reference.html NSUInteger是无符号的整型, NSInteger是有符号的整型,在表视图应用中常见 NSUInteger row= [indexPath row];因为这是显示tableViewCell有多少个,只能是非零整数的,也就是说

.net Mvc Controller 接收 Json/post方式 数组 字典 类型 复杂对象

原文地址:http://www.cnblogs.com/fannyatg/archive/2012/04/16/2451611.html ------------------------------------------------------------------------------------------------------------------ Asp.net Mvc Controller Json数组接收数组字典 类型 复杂对象 方法一,(最复杂的方法)扩展ModelBin

You are using the runtime-only build of Vue where the template compiler is not available. Either pre

在升级脚手架到vue-cli3.0版本的时候出现了这个报错: [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build. 我在这里大概说一下出现这个报错的原因在哪里和解决办

Vue数组双向绑定内幕

在Vue使用期间,我们经常会遇到对于数组的操作,但是Vue中如何实现数组双向绑定的呢,在这篇PPT中,首先回顾Vue双向绑定原理,之后再去研究Vue对于数组的特殊处理. ppt:Vue数组双向绑定内幕 参考:https://ustbhuangyi.github.io/vue-analysis/ 原文地址:https://www.cnblogs.com/MarphyDemon/p/11487764.html

[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available

原文链接https://blog.csdn.net/xiaomajia029/article/details/88320233 问题描述: 原因分析:在项目配置的时候,默认 npm 包导出的是运行时构建,即 runtime 版本,不支持编译 template 模板. vue 在初始化项目配置的时候,有两个运行环境配置的版本:Compiler 版本.Runtime 版本. 其主要区别在于: Compiler 版本:可以对 template 模板内容进行编译(包括字符串模板和可以绑定的 html 对

vue 数组

今天项目中发现的一个问题: 在vue项目中输出一个数组,明明有俩个值:0,6,但是length为1 正常的是这样的 结果研究发现,是vue源码的问题,具体内容如下: 转载自:http://www.cnblogs.com/Darlietoothpaste/p/6682407.html Vue的数组操作的实现代码大致如下: 1 const aryMethods = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse']; 2