vuex--state的使用

方法1直接调用

在store.js中state中写
例如

state:{
count: 0
}

在组件中调用
{{}}方法调用例如

{{$store.state.count}}

方法2导入法

在store.js中state中写
例如

state:{
count: 0
}

在调用的组件中使用
首先导入

import { mapState } from 'vuex'

然后再

computed: {
...mapState(['count'])
}

猜你喜欢

转载自blog.csdn.net/weixin_43755104/article/details/107620391