Vue中vuex状态管理state用法

1,组件直接用法

 <div>{{$store.state.num}}</div>

2,计算属性里面用法

 <div>{{num}}</div>

computed:{

   num(){

     return this.$store.state.num

}

}

3,用mapState

 <div>{{num}}</div>

import { mapState } from 'vuex'

computed:{

  ...mapState(['num'])

}

posted @ 2025-12-27 13:41  学无边涯  阅读(5)  评论(0)    收藏  举报