```javascript
<template>
<view class="uni-container">
<button @click="arrayInit">array添加项</button>
<button @click="arrayEmpty">array变为空数组</button>
<view>array.length > 0 的值 {{ array.length > 0 }}</view>
<view v-show="array.length > 0">v-show中array.length大于0展示</view>
<view v-if="array.length > 0">v-if中array.length大于0展示</view>
</view>
</template>
<script>
export default {
data() {
return{
array: [],
isShow: false
}
},
methods: {
arrayInit() {
this.array = [1,2,3,4];
},
arrayEmpty() {
this.array = [];
}
},
}
</script>
```
点击"array添加项"按钮,会为array赋值为[1,2,3,4]
预期结果
“v-show中array.length大于0展示”内容展示出来
“v-if中array.length大于0展示”内容展示出来
实际结果
“v-show中array.length大于0展示”内容没有展示出来
“v-if中array.length大于0展示”内容展示出来
由上图可知,array的更改并没有触发v-show这块dom的更新
问了下uniapp的github上面的issus,uniapp中针对数组底层都是差量更新,而微信小程序中使用hidden="{{array.length}}"针对数组差量更新并不会动态更新,链接https://developers.weixin.qq.com/community/develop/doc/000c8ee47d87a0d5b6685a8cb57000