0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Vue.js:ストアについて

Posted at

Vueのストアを勉強するため、その処理を使ったアプリをそれなりになるまで作ってみようと思います。

VueCliでプロジェクトを作成し、storeフォルダのindex.jsと、viewフォルダの中のAboutView.viewに手を加え練習しました。

store/index.js
import { createStore } from 'vuex'

export default createStore({
  state: {
    catName:'ねこ'
  },
  getters: {
  },
  mutations: {
    get(state){
      return state
    }
  },
  actions: {
  },
  modules: {
  }
})
view/AboutView.vue
<template>
  <div class="form">
    <div class="body">
      <div>
        <p class="cname">ねこのなまえ</p>
        <p class="catName">{{catName}}</p>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  name: 'catName',
  computed: {
    catName:{
        get(){
          return this.$store.state.catName
        }
    }
  }
}
</script>

とりあえず画面にストアの値を表示することはできました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?