#Vue#Nuxt 초보자를 위한 – Vuex에서store를 사용하여 버튼을 누르면 수량이 증가하는 간단한 카운터를 만들 수 있습니다(simple counter example)
NOTE
yarn create nuxt-app my-project
store/increments.js
export const state = () => ({
count: 1
})
export const mutations = {
increment (state) {
state.count++
},
}
pages/increment.vue
{{ count }}
과 연결$store.commit
의 매개 변수는 $store.commit('storeのファイル名/storeの関数名)
의 형식으로 대응하는 것 같다
// https://nuxtjs.org/guide/vuex-store/
<template>
<div>
<div>
<h1> {{ count }} </h1>
<input type="button" @click="incrementCounter" value="Increment!">
</div>
</div>
</template>
<script>
export default {
computed: {
count () {
return this.$store.state.increments.count
}
},
methods: {
incrementCounter (e) {
this.$store.commit('increments/increment')
}
}
}
</script>
<style>
body {
text-align: center;
}
</style>
행위
yarn dev에서 시작할 때
액세스 http://localhost:3000/increment 및 버튼 누름
참고 자료
왜 카운터의 예와 TODO 목록의 예가 함께 나타나는지...
고전 모드, 모듈 모드, state, mutation, 쓰기 종류가 잘 모르겠어요. 공식 문서도 너무 단편적이어서 싫어요.
Original by Github issue
Reference
이 문제에 관하여(#Vue#Nuxt 초보자를 위한 – Vuex에서store를 사용하여 버튼을 누르면 수량이 증가하는 간단한 카운터를 만들 수 있습니다(simple counter example)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/0f1f09d347686f35ebf3
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
왜 카운터의 예와 TODO 목록의 예가 함께 나타나는지...
고전 모드, 모듈 모드, state, mutation, 쓰기 종류가 잘 모르겠어요. 공식 문서도 너무 단편적이어서 싫어요.
Original by Github issue
Reference
이 문제에 관하여(#Vue#Nuxt 초보자를 위한 – Vuex에서store를 사용하여 버튼을 누르면 수량이 증가하는 간단한 카운터를 만들 수 있습니다(simple counter example)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/0f1f09d347686f35ebf3
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(#Vue#Nuxt 초보자를 위한 – Vuex에서store를 사용하여 버튼을 누르면 수량이 증가하는 간단한 카운터를 만들 수 있습니다(simple counter example)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/YumaInaura/items/0f1f09d347686f35ebf3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)