父组件是一个对象数组,子组件也是对象数据。点击按钮后,对象上的expand变为true或者false,控制界面的折叠和展开。
父组件都没有问题,子组件expand一直为false。
父组件代码:
。。。
<q-tr v-show="props.row.expand" :props="props">
<q-td colspan="100%" style="padding: 7px;">
<div v-if="props.row.gauges[0]">{{props.row.gauges[0].expand}}</div>
<plant-gauges :profile="props.row" :gauges="props.row.gauges"></plant-gauges>
</q-td>
</q-tr>
</template>
子组件:点击展开,变量和界面均没有响应。
import plantRanges from './plantRanges.vue'
export default {
name: 'plant-gauges',
props: {
profile: {
type: Object,
default () {
return {}
}
},
gauges: {
type: Array,
default () {
return []
}
}
},
gaugeExpand (profileID, stype) {
this.$store.dispatch('plants/gaugeExpand', { profileID: profileID, stype: stype })
},
store mutation代码:
export function gaugeExpand (state, Obj) {
var index = state.plantProfiles.findIndex((profile) => (profile._id === Obj.profileID))
if (index > -1) {
let profile = state.plantProfiles[index]
var gaugeIndex = profile.gauges.findIndex((gaugeObj) => (gaugeObj.stype === Obj.stype))
if (gaugeIndex > -1) {
var gauge = profile.gauges[gaugeIndex]
gauge.expand = !gauge.expand
Vue.set(state.plantProfiles, index, profile)
}
}
}
加多一个prop,
<plant-gauges :profile="props.row" :expand="props.row.expand" :gauges="props.row.gauges"></plant-gauges>
或者在子组件那里watch props.row