import {mapState} from 'vuex'
export default {
data(){
return {
oldData: 0
}
}
computed: mapState({
count: state => state.count,
newData(){
return this.oldData + 1;
}
})
}
这样子写吗?
import {mapState} from 'vuex'
export default {
data(){
return {
oldData: 0
}
}
computed: mapState({
count: state => state.count,
newData(){
return this.oldData + 1;
}
})
}
这样子写吗?
import { mapState } from 'vuex'
export default {
data () {
return {
localCount: 1
}
},
// mapState 辅助函数帮助我们生成计算属
computed: mapState({
// 箭头函数可使代码更简练
count: state => state.count,
// 传字符串参数 'count' 等同于 'state => state.count'
countAlias: 'count',
// 为了能使用 'this'获取局部状态,必须使用常规函数
countPlusLocalState (state) {
return state.count + this.localCount
},
// 常规 computed, 没有使用 store的状态
localCountAlias () {
return this.localCount
}
})
}
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
5 回答1.9k 阅读