IT이야기

VueJS 두 매개 변수를 Vuex 작업에 전달하는 방법

cyworld 2022. 5. 26. 23:07
반응형

VueJS 두 매개 변수를 Vuex 작업에 전달하는 방법

<button class="btn" @click="removeFromTheCart(index,item.price)">
  Remove
</button>

두 개의 매개 변수를 내 액션에 전달하고 있어. from TheCart.

removeFromTheCart({ commit }, payload) {
  console.log("rooooooohhhhhoooow",payload)

vuex 저장소에 내 페이로드를 기록할 때 인덱스만 출력한다.내 두 번째 파라미터는 출력되지 않았다.

작업을 통해 두 개의 매개 변수 값을 얻는 방법

다음과 같이 물체를 페이로드로 보낼 수 있다.

<button class="btn" @click="removeFromTheCart({ index, price: item.price })">Remove</button>

그리고 저장소에 있는 데이터를 가져오십시오.

removeFromTheCart({ commit }, { index, price }) {
  console.log('index', index, 'price', price);
}

참조URL: https://stackoverflow.com/questions/49998296/vuejs-how-to-pass-two-parameters-to-an-vuex-action

반응형