123456789101112131415161718192021222324252627282930 |
- import { createSlice } from "@reduxjs/toolkit";
- /**
- * 抛出:
- * export default
- * export const xxxx = 值
- * export function xxx = 方法
- */
- // 1.创建切片
- // 2.定义切片
- // 3.抛出切片
- export const countSlice = createSlice({
- name: 'Count',//唯一性
- // 定义状态初始值
- initialState: {
- value: 0
- },
- reducers:{
- addNum(state,action) {
- state.value++;
- },
- reduceNum(state,action) {
- state.value--;
- }
- }
- })
- export default countSlice.reducer;
- export const {addNum,reduceNum} = countSlice.actions
|