请选择 进入手机版 | 继续访问电脑版
帖子
帖子
用户
博客
课程
显示全部楼层
286
帖子
2
勋章
7万+
Y币

[多端开发] 咋回事, vfor 炸了?

[复制链接]
发表于 2021-7-10 14:11:58
今天用vfor 写了一下代码,怎么提示 ReferenceError: index$1 is not defined 这个错误

代码如下:
  1. <template>
  2.         <view v-for="(item,index) in Array.from(length:5)"
  3.                 :class="activeSwiperIndex == index ? 'swiper-actvie':'swiper-nomarl'"></view>
  4. </template>
  5. <style>
  6. </style>
  7. <script>
  8. export default {
  9.         name: 'test',
  10.         data() {
  11.                 return {
  12.                         activeSwiperIndex: 0
  13.                 }
  14.         },
  15.         methods: {
  16.         }
  17. }
  18. </script>
复制代码
经过编译后的文件内容如下
iShot2021-07-10 14.11.32.png
380
帖子
4
勋章
6
Y币
已反馈给相关技术确认解决
20
帖子
1
勋章
7559
Y币
你的代码存在问题:
1、没有 Array.from(length:5) 这种写法
2、template节点下必须包含一个根视图,你在根视图是直接进行v-for,循环出来的视图都是子视图,没有父节点包裹。
286
帖子
2
勋章
7万+
Y币
常山赵子云 发表于 2021-10-20 12:23
你的代码存在问题:
1、没有 Array.from(length:5) 这种写法
2、template节点下必须包含一个根视图,你在根 ...

那现在 v-for 里面能直接 类似(item,index)in 6  这种方式了吗?因为发帖的时候,这种方式还是不支持的
20
帖子
1
勋章
7559
Y币
忽上忽下 发表于 2021-10-20 13:30
那现在 v-for 里面能直接 类似(item,index)in 6  这种方式了吗?因为发帖的时候,这种方式还 ...

不支持。in条件目前支持数组和对象。
10
帖子
1
勋章
5640
Y币
应该是  Array.from( {length:5} )
Array.from 传递一个类数组(即有length属性的对象)
忽上忽下 · 2021-10-20 13:30那现在 v-for 里面能直接 类似(item,index)in 6  这种方式了吗?因为发帖的时候,这种方式还是不支持的

您需要登录后才可以回帖 登录

本版积分规则