weex页面一个组件绑定了一个对象的某个属性,在created方法中,我调用了原生注册好的一个自定义module中的方法,这个方法在callback中,回调了一个字符串,在weex这边收到回调时,对绑定的对象的属性值进行修改,然后对应绑定的组件视图会刷新,但是,这个页面多次返回再打开,会偶尔出现,属性值已经改变,但是视图不更新的问题。
(这个组件是一个自定义组件,绑定的对象传入到子组件之后,在子组件里更新视图。经过测试,我在当前页面的组件更新数据,页面是会刷新,不会出现不刷新的情况,但是这个子组件会偶尔出现不刷新)
父组件的模板,my-normalitem
是子组件
<template>
<div class="wrapper">
<list class="list">
<header class="header"></header>
<cell v-for="item in test">
<my-normalitem :item="item" @itemClicked="onItemClicked"></my-normalitem>
</cell>
</list>
</div>
</template>
script:
export default {
data () {
return {
test: [{
icon: '../assets/images/my/content_Clear.png',
title: '清除本地缓存',
info: '',
showArrow: false,
index: 4,
}]
}
}
在created方法里,会调用下面这个getCache方法,这里使用了原生新增的一个modul方法,获取了本地的一个字符串,然后更新数据源。我输出过this.test[0].info的值,每次都会输出正确的值,但是有的时候,就会输出值是正确的,但是视图并没有更新,还是默认值
methods: {
getCache(){
commonmodal.getCache( event => {
if (!(event === undefined)) {
const tmpInfo = this.test[0]
tmpInfo.info = event
this.test.$set(0, tmpInfo)
}
})
},
下面是子组件的模板
<template>
<div class="wrapper" @click="onClickItem">
<image class="icon" :src="item.icon"></image>
<text class="text">{{item.title}}</text>
<div class="right">
<div class="infoWrapper" :style="{right: infoWrapperRight}">
<text class="info" >{{item.info}}</text>
</div>
<image class="arrow" src="../assets/images/my/content_direction.png" v-if="item.showArrow"></image>
</div>
<div class="line"></div>
</div>
</template>
你贴出你自定义组件、调用组件、属性更新的代码,你上依赖怎么看的出呢