对 state 中的数组使用 v-model

./store/state.js

export default {
  userInfo: { name: '' },
}

./store/mutations.js

export default {
  UPDATE_NAME(state, payload = {}) {
    state.userInfo.name = payload.name
  },
}

./store/mutations.js

export default {
  UPDATE_NAME(state, payload = {}) {
    state.userInfo.name = payload.name
  },
}

App.vue

<template>
  <div>
    <input type="text" v-model="name" />
    <span>{{ userInfo.name }}</span>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  computed: {
    ...mapState(['userInfo']),
    name: {
      get() {
        return this.userInfo.name
      },
      set(name) {
        this.$store.commit('UPDATE_NAME', { name })
      },
    },
  },
}
</script>
上一篇:xss技巧之绕过script和svg的过滤


下一篇:http-smuggling