【发布时间】:2017-09-06 09:34:53
【问题描述】:
我的 vue 组件是这样的:
<template>
<div>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label for="status" class="sr-only">Status</label>
<select class="form-control" v-model="selected" @change="filterByStatus()">
<option value="">All Status</option>
<option v-for="status in orderStatus" v-bind:value="status.id">{{ status.name }}</option>
</select>
</div>
</div>
</div>
...
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex';
export default {
...
data() {
return { selected: '' }
},
methods: {
filterByStatus: function() {
this.$store.state.status = this.selected
}
}
}
</script>
我的模块顺序 vuex 是这样的:
import { set } from 'vue'
import order from '../../api/order'
import * as types from '../mutation-types'
const state = {
status: ''
}
const getters = {
...
}
const actions = {
...
}
const mutations = {
...
}
export default {
state,
getters,
actions,
mutations
}
我使用这个:this.$store.state.order.status = this.selected,在执行时更新状态,但存在这样的错误:
[Vue 警告]:观察者回调错误“function () { return this._data.$$state }":(在 中找到)
错误:[vuex] 不要在突变之外改变 vuex 存储状态 处理程序。
我该如何解决?
我想要更新状态,因为我想要另一个组件使用的值
【问题讨论】:
标签: vue.js vuejs2 vue-component vuex