比如傳給子組件的item參數(shù)值是0 但是子組件視圖會(huì)報(bào)錯(cuò)Cannot read property 'info' of undefined"如果把計(jì)算屬性里面的[this.index]改成[0]的話可以正常渲染視圖 但是下面這樣寫就不行 各個(gè)生命周期都試了 都不行怎么辦<template>
<div>
{{data.info}} </div></template>import { mapState } from 'vuex'data () { return {
index: ''
}
},
computed: {
...mapState({ data: state => state.userList[this.index]
})
},
created () { this.index = this.$route.query.item
},
2 回答

函數(shù)式編程
TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
你初始化時(shí)的index='',computed中的this.index為'',返回的data值時(shí)undefined,mounted之后index才改變
添加回答
舉報(bào)
0/150
提交
取消