为什么我从 vue.js 组件脚本中的一个简单的 for 循环中收到“我未定义"错误? [英] why am i getting 'i is not defined' error from a simple for loop in vue.js component script?

查看:70
本文介绍了为什么我从 vue.js 组件脚本中的一个简单的 for 循环中收到“我未定义"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个数组,按版本对该数组进行排序,然后将所有以ipad"开头的版本移动到列表的末尾.

I'm trying to taking an array, order that array by version, and then moving all versions that begin with 'ipad' to the end of the list.

来自单个文件 vue.js 组件的片段:

snippet from single file vue.js component:

  computed: {
    orderedUsers: function () {
      let newArray = sortBy(this.jobs, 'version').reverse()
      for (i in newArray) {
        if (i.version.startsWith('iPad')) {
          newlist.push(newlist.splice(i, 1)[0]);
        }
      }
      return newArray
  },

错误:

vue.runtime.esm.js?e832:619 [Vue warn]: Error in render: "ReferenceError: i is not defined"

不确定这是一个js问题还是一个vue.js问题

Not sure if this is a js question or a vue.js question

推荐答案

尝试在 for 循环中使用 let i 之前添加它.请参阅下面的示例.

Try to add let i before using it in the for loop. See example below.

for (let i in newArray) {
  if (i.version.startsWith('iPad')) {
    newlist.push(newlist.splice(i, 1)[0]);
  }
}

这篇关于为什么我从 vue.js 组件脚本中的一个简单的 for 循环中收到“我未定义"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆