Skip to content

Instantly share code, notes, and snippets.

@hjkcai
Last active July 16, 2017 04:15
Show Gist options
  • Save hjkcai/eddb62be911e7e66d18a65d06d783c1d to your computer and use it in GitHub Desktop.
Save hjkcai/eddb62be911e7e66d18a65d06d783c1d to your computer and use it in GitHub Desktop.
嵌套组件中同时出现wx:for和repeat会导致repeat中循环变量失效
<template>
<view class="comp">
<slot></slot>
</view>
</template>
<script>
import wepy from 'wepy'
export default class Comp extends wepy.component {}
</script>
<template>
<view>
<wrapper></wrapper>
</view>
</template>
<script>
import wepy from 'wepy'
import wrapper from './wrapper'
export default class Index extends wepy.page {
components = {
wrapper
}
}
</script>
<template>
<view id="wrapper">
<view id="for1">
<view wx:for="{{ arr1 }}">{{ item }}</view>
</view>
<view id="for2">
<repeat for="{{ arr2 }}">
<comp>{{ item }}</comp>
</repeat>
</view>
</view>
</template>
<script>
import wepy from 'wepy'
import comp from './comp'
export default class Wrapper extends wepy.component {
components = {
comp
}
data = {
arr1: ['a', 'b', 'c'],
arr2: ['1', '2', '3']
}
}
</script>
<template>
<view id="wrapper">
<view id="for1">
<view wx:for="{{ arr1 }}" wx:for-item="for1Item" wx:for-index="for1Index">{{ for1Item }}</view>
</view>
<view id="for2">
<repeat for="{{ arr2 }}">
<comp>{{ item }}</comp>
</repeat>
</view>
</view>
</template>
<script>
import wepy from 'wepy'
import comp from './comp'
export default class Wrapper extends wepy.component {
components = {
comp
}
data = {
arr1: ['a', 'b', 'c'],
arr2: ['1', '2', '3']
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment