有兩種寫法
1.首先在組件中引入vuex的mapState方法:
首先在組件中引入vuex的mapState方法:
import { mapState } from 'vuex'
然后在computed中這樣寫:
computed:{
...mapState({
save:state => state.save//使用ES6的箭頭函數來給count賦值
})
}
2.需要先在組件中引入vuex的mapState方法:
import { mapState } from 'vuex'
然后在computed中這樣寫:
computed:
...mapState([' save'])
}