首页 > 其他分享 >Vue 急速入门2

Vue 急速入门2

时间:2023-02-15 16:01:02浏览次数:36  
标签:Vue 入门 &# -- 45 索引 急速 循环 ndash

内容概要

Js的几种循环方式

v-for可以循环的变量
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="vue/vue.js"></script>
</head>
<body>
<div class="app">

<!--v-for能循环的数据类型-->
<h1>v-for循环</h1>

<!--<h2>循环数组</h2>-->
<!--<p v-for="goods in goodList">{{goods}}</p>-->
<!--<h2>循环数组带索引</h2>-->
<!--    <p v-for="(good,index) in goodList">{{index}}-&#45;&#45;&#45;&#45;{{good}}</p> &lt;!&ndash;k为字符串内容v为字符串索引&ndash;&gt;-->
<!--<h2>循环字符串</h2>-->
<!--<p v-for="i in name">{{i}}</p>-->
<!--<p v-for="(k,v) in name">{{k}}-&#45;&#45;&#45;&#45;{{v}}</p> &lt;!&ndash;k为字符串内容v为字符串索引&ndash;&gt;-->

<!--<h2>循环对象</h2>-->
<!--<p v-for="(k,v) in info">{{k}}-&#45;&#45;&#45;&#45;{{v}}</p>   &lt;!&ndash;k为值,v为k&ndash;&gt;-->
<!--<p v-for="i in info">{{i}}</p>   &lt;!&ndash;i为值&ndash;&gt;-->


</div>
</body>
<script>
    let vm = new Vue({
        el:'.app',
        data:{
            goodList:['美女','汽车',"报纸","香槟"],
            name:"刘亦菲真好看我就喜欢看",
            info:{tureName: 'meiren', age: 19,}
        },
        methods:{}
    })
</script>
</html>

总结:
数组循环: i in xx i为数组中的每一个数据
数组循环带索引: k,v in xx k为数组中的每一个数据 v为索引
字符串循环 i in xx i 为字符串中的每一个数据
字符串循环带索引:k,v in xx k为字符串内容v为字符串索引
对象循环 i in xx i 为对象的每一个数据的值
对象循环带索引 k,v in xx k为对象每一个数据的值,v为对象每一个数据的键

js的循环方式
js中5中循环方式!
python都是基于迭代的循环,没有基于索引的循环
// 第一种 基于索引的循环 拿到的i 为索引
   var a = [4, 5, 6, 7]
    for (i = 0; i < a.length; i++) {
        console.log(i)
        // console.log(a[i])
    }
// 第二种 js 中 in 循环 拿到的 i 为索引
var list=[4,5,6,7]
for (i in list){
	console.log(i)
	console.log(a[i])
}
// 第三种 js 中 es6语法 of 循环 拿到的i为值
   var list = ['美女','汽车',"报纸","香槟"]
    for (i of list){
        console.log(i) 
}
// 第四种 js数组自带方法forEach i 为 值
   var list = ['美女','汽车',"报纸","香槟"]
    list.forEach((i)=> {
        console.log("-",i)
    })
// 第五种 jquery 中的循环 index为索引,value为数组中的值
导入jquery
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
   var list = ['美女','汽车',"报纸","香槟"]
    $.each(list,(index,value)=> {
        console.log(index,"---",value)
    })

标签:Vue,入门,&#,--,45,索引,急速,循环,ndash
From: https://www.cnblogs.com/ddsuifeng/p/17123244.html

相关文章

  • vue中渲染数据时的计算
    如果后端返回的数据需要简单的处理,比如需要截取、字段间的简单计算之类的操作可以直接在渲染中使用字段间的计算:{{Number(`${product.PlanNum}`)+Number(`${product.Sum......
  • Vue 自定义指令-directive
    什么是自定义指令vue官方提供了v-text、v-for、v-model、v-if等常用的指令。除此之外vue还允许开发者自定义指令。局部自定义指令的使用<body><divid="app">......
  • Vue 自定义指令-directives
    什么是自定义指令vue官方提供了v-text、v-for、v-model、v-if等常用的指令。除此之外vue还允许开发者自定义指令。局部自定义指令的使用<body><divid="app">......
  • Java入门
    一、了解Java1.JAVA三大版本Java2标准版(J2SE):桌面程序(控制台开发)Java2移动版(J2ME):嵌入入式开发(手机小家电)Java2企业版(J2EE):企业级开发(web端,服务......
  • vue-day02插值语法、文本指令、属性指令、事件指令、class和style、条件渲染、列表渲
    目录一、插值语法1.1mvvm演示1.2插值语法二、文本指令三、属性指令四、事件指令五、class和style六、条件渲染七、列表渲染八、补充:九、作业一、插值语法1.1mvvm演示......
  • vue-seamless-scroll 组件用法-区域内容滚动效果
    1.滚动效果2.代码<divclass="page-container"style=""><vue-seamless-scroll:data="listData":class-option="defaultOption"><ulclass="ul-scol......
  • eslint vue
    1、Error[ERR_REQUIRE_ESM]:require()ofESModulepackage.json中"type":"module"移除2、Cannotfindmodule'./App.vue'oritscorrespondingtypedeclarations......
  • Vue Grid Layout -️ 适用Vue.js的栅格布局系统(自定义页面)
    官网:https://jbaysolutions.github.io/vue-grid-layout/zh/github:https://github.com/jbaysolutions/vue-grid-layout 一个类似于Gridster的栅格布局系统,适用于Vue.j......
  • vue2+element表格拖拽
    1、定义好拖拽元素ref标识,以及 row-key="id" (row-key拖拽标识,拖拽后数据不会乱,id为tableDataNew数据对象id)2、下载cnpminstallsortablejs--save插件,并引入 impo......
  • 更换电脑运行Vue项目, npm run不起来的问题记录
    问题1:AssertionFailedExpression:thread_id_key!=0x7777Forinformationonhowyourprogramcancauseanassertionfailure,seethevisualC++documentation......