dcloudio / uni-app

A cross-platform framework using Vue.js
https://uniapp.dcloud.io
Apache License 2.0
40.14k stars 3.63k forks source link

20200812版本for循环内部无法获取for定义的变量 #2014

Closed pakholeung37 closed 4 years ago

pakholeung37 commented 4 years ago

问题描述 微信小程序v-for="(item, index) in items"循环的内部获取不到定义的item或index, 我手上的代码有大量这样的错误 相关代码片段

   <view
        class="nav_wrapper navitemWrap"
        v-for="(item, index) in moduleContent.moduleList"
        :key="index"
        :data-index="index"
        @click="switchNav"
      >
        <view
          class="ellipsis nav_item"
          :class="{
            active: index === selectIndex,
            style_0: moduleContent.style == 0,
            style_1: moduleContent.style == 1,
          }"
          :style="
            index === selectIndex ? getActiveNavStyle(moduleContent.style) : ''
          "
          >{{
            item.moduleInfo ? item.moduleInfo.content.title : item.name
          }}</view
        >
        <view
          class="item_border"
          v-if="moduleContent.style == 1 && index == selectIndex"
          :style="
            index == selectIndex
              ? getActiveNavBorderStyle(moduleContent.style)
              : ''
          "
        ></view>
</view>

error

[Vue warn]: Property or method "index" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

found in

---> <Label> at components/modules/label/label.vue
       <Index> at components/moduleContainer/index.vue
         pages/index/index.vue

编译出来的render

var render = function() {
  var _vm = this
  var _h = _vm.$createElement
  var _c = _vm._self._c || _h
  var m0 =
    _vm.index === _vm.selectIndex
      ? _vm.getActiveNavStyle(_vm.moduleContent.style)
      : null
  var m1 =
    _vm.moduleContent.style == 1 &&
    _vm.index == _vm.selectIndex &&
    _vm.index == _vm.selectIndex
      ? _vm.getActiveNavBorderStyle(_vm.moduleContent.style)
      : null
  _vm.$mp.data = Object.assign(
    {},
    {
      $root: {
        m0: m0,
        m1: m1
      }
    }
  )
}

复现步骤 [复现问题的步骤]

[或者可以直接贴源代码]

预期结果 实际结果

系统信息:

补充信息 我手上的版本0812, 在上一个版本是没问题的, 看到changelog有提到更改过for循环的相关代码, 是不是影响到了?

zhetengbiji commented 4 years ago

2011

gkl2013 commented 4 years ago

还没解决么