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 3 years have passed since last update.

Vuexとbootstrap-vueを組み合わせた実装

Posted at

Vuexとbootstrap-vueを組み合わせた実装

忘れ内容にメモ

store作成

まず、Vuexでstoreを作成

store/sample.ts
export const state = () => ({
  id: '',
  name: ''
})

export State = {
  id: string
  name: string
}

export const mutations = {
  changeId(state: State, value: string) {
    state.id = value
  },
  changeName(state: State, value: string) {
    state.name = value
  },
}

computedでgetterとsetter

index.vue
  computed: {
    id: {
      get () {
        return this.$store.state.sample.id
      },
      set (val) {
        this.id(val)
      }
    },
    name: {
      get () {
        return this.$store.state.sample.name
      },
      set (val) {
        this.name(val)
      }
    }

computedで定義したものを後は b-form-input などのmodelに渡すだけ

vee-validateなどを使用した場合(pug)

validation-observer(ref="observer" v-slot="{ handleSubmit, invalid }")
  b-form(@submit.prevent="handleSubmit(onSubmit)")
    validation-provider(
      name="id"
      v-slot="{ errors, valid, validated }"
    )
      b-form-input(
        v-model="id"
        :state="validated ? valid : null"
      )
      b-form-invalid-feedback {{ errors[0] }}
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?