3
我VUE组分是这样的:如何更新vuex中的状态? vue.js 2
<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 warn]: Error in callback for watcher "function() { return this._data.$$state }": (found in)
Error: [vuex] Do not mutate vuex store state outside mutation handlers.
我该如何解决它?
我想更新的状态,因为我想通过组件使用的值的另一